qdev: bus management updates.
cover qdev: bus management updates.
Hi,
This patch series does a bunch of improvements for qdev busses. The former name was "allow embedded bus structs", but that title doesn't cut it any more as there are lots of followup improvements and fixes. Changes:
* allow embedded bus structs (yes, still there).
* add bus release function.
* added device destruction callback to qdev devices.
* make busses use the new features.
End result is that you can use qdev_free() to zap a device. Using the destruction callback everything will be released properly. qdev will walk the child bus(es) if present and zap all connected devices too.
You can pci_del the scsi adapter and all scsi disks will be deleted too. You can pci_del the usb controller and all usb devices connected will be deleted too. You can unplug usb hubs, all connected devices will go away too.
cheers,
Gerd
PATCH 1/13 allow qdev busses allocations be inplace
A bus usually is instanciated by the parent device. The accociated bus state can usually be embeeded into the parent device state struct, there is no need for separate allocation and pointer indirection.
This patch adds a non-allocating qbus_create variant. We keep track of whenever qdev allocated the struct or not. Will be needed later in this patch series when we'll fix bus unplugging.
--- hw/qdev.c | 15 ++++++++++++--- hw/qdev.h | 3 +++ 2 files changed, 15 insertions(+), 3 deletions(-)
hw/qdev.c +12 -3
@@ -502,13 +502,12 @@ static BusState *qbus_find(const char *path) } } -BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name) +void qbus_create_inplace (BusState *bus,BusInfo *info, +DeviceState *parent,const char *name) { -BusState *bus;char *buf;int i,len; - bus =qemu_mallocz (info->size); bus->info = info; bus->parent = parent;
@@ -537,6 +536,16 @@ BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)QLIST_INSERT_HEAD (&parent->child_bus, bus, sibling); parent->num_child_bus++; } + +} + +BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name) +{ +BusState *bus; + + bus =qemu_mallocz (info->size); + bus->qdev_allocated =1 ; +qbus_create_inplace (bus, info, parent, name);return bus; }
hw/qdev.h +3 -0
@@ -47,6 +47,7 @@ struct BusState {DeviceState *parent;BusInfo *info;const char *name; +int qdev_allocated; QLIST_HEAD(, DeviceState) children;QLIST_ENTRY (BusState) sibling; };
@@ -144,6 +145,8 @@ BusState *qdev_get_parent_bus(DeviceState *dev);/*** BUS API. ***/ +void qbus_create_inplace (BusState *bus,BusInfo *info, +DeviceState *parent,const char *name);BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name);#define FROM_QBUS (type, dev) DO_UPCAST(type, qbus, dev)
Signature · 1 line
1.6.2.5
PATCH 2/13 switch scsi bus to inplace allocation.
In reply to Gerd Hoffmann--- hw/esp.c | 10 +++++----- hw/lsi53c895a.c | 12 ++++++------ hw/scsi-bus.c | 9 +++------ hw/scsi-disk.h | 4 ++-- hw/usb-msd.c | 6 +++--- 5 files changed, 19 insertions(+), 22 deletions(-)
hw/esp.c +5 -5
@@ -63,7 +63,7 @@ struct ESPState {uint8_t ti_buf[TI_BUFSZ ];uint32_t sense;uint32_t dma; -SCSIBus *bus; +SCSIBus bus;SCSIDevice *current_dev;uint8_t cmdbuf[TI_BUFSZ ];uint32_t cmdlen;
@@ -191,7 +191,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf) s->async_len =0 ; } -if (target >=ESP_MAX_DEVS || !s->bus->devs[target]) { +if (target >=ESP_MAX_DEVS || !s->bus.devs[target]) {// No such drive s->rregs[ESP_RSTAT ] =0 ; s->rregs[ESP_RINTR ] =INTR_DC ;
@@ -199,7 +199,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf)esp_raise_irq (s);return 0 ; } - s->current_dev = s->bus->devs[target]; + s->current_dev = s->bus.devs[target];return dmalen; }
@@ -672,8 +672,8 @@ static int esp_init1(SysBusDevice *dev)qdev_init_gpio_in (&dev->qdev, parent_esp_reset,1 ); - s->bus =scsi_bus_new (&dev->qdev,0 ,ESP_MAX_DEVS , esp_command_complete); -scsi_bus_legacy_handle_cmdline (s->bus); +scsi_bus_new (&s->bus, &dev->qdev,0 ,ESP_MAX_DEVS , esp_command_complete); +scsi_bus_legacy_handle_cmdline (&s->bus);return 0 ; }
hw/lsi53c895a.c +6 -6
@@ -193,7 +193,7 @@ typedef struct {* 2 if processing DMA from lsi_execute_script. * 3 if a DMA operation is in progress. */ int waiting; -SCSIBus *bus; +SCSIBus bus;SCSIDevice *current_dev;int current_lun;/* The tag is a combination of the device ID and the SCSI tag. */
@@ -585,7 +585,7 @@ static void lsi_reselect(LSIState *s, uint32_t tag) id = (tag >>8 ) &0xf ; s->ssid = id |0x80 ;DPRINTF ("Reselected target %d\n" , id); - s->current_dev = s->bus->devs[id]; + s->current_dev = s->bus.devs[id]; s->current_tag = tag; s->scntl1 |=LSI_SCNTL1_CON ;lsi_set_phase (s,PHASE_MI );
@@ -1041,7 +1041,7 @@ again: } s->sstat0 |=LSI_SSTAT0_WOA ; s->scntl1 &= ~LSI_SCNTL1_IARB ; -if (id >=LSI_MAX_DEVS || !s->bus->devs[id]) { +if (id >=LSI_MAX_DEVS || !s->bus.devs[id]) {DPRINTF ("Selected absent target %d\n" , id);lsi_script_scsi_interrupt (s,0 ,LSI_SIST1_STO );lsi_disconnect (s);
@@ -1052,7 +1052,7 @@ again:/* ??? Linux drivers compain when this is set. Maybe it only applies in low-level mode (unimplemented). lsi_script_scsi_interrupt(s, LSI_SIST0_CMP, 0); */ - s->current_dev = s->bus->devs[id]; + s->current_dev = s->bus.devs[id]; s->current_tag = id <<8 ; s->scntl1 |=LSI_SCNTL1_CON ;if (insn & (1 <<3 )) {
@@ -2178,8 +2178,8 @@ static int lsi_scsi_init(PCIDevice *dev)lsi_soft_reset (s); - s->bus =scsi_bus_new (&dev->qdev,1 ,LSI_MAX_DEVS , lsi_command_complete); -scsi_bus_legacy_handle_cmdline (s->bus); +scsi_bus_new (&s->bus, &dev->qdev,1 ,LSI_MAX_DEVS , lsi_command_complete); +scsi_bus_legacy_handle_cmdline (&s->bus);register_savevm ("lsiscsi" ,-1 ,0 , lsi_scsi_save, lsi_scsi_load, s);return 0 ; }
hw/scsi-bus.c +3 -6
@@ -15,17 +15,14 @@ static struct BusInfo scsi_bus_info = {static int next_scsi_bus;/* Create a scsi bus, and attach devices to it. */ -SCSIBus *scsi_bus_new (DeviceState *host,int tcq,int ndev, -scsi_completionfn complete) +void scsi_bus_new (SCSIBus *bus,DeviceState *host,int tcq,int ndev, +scsi_completionfn complete) { -SCSIBus *bus; - - bus =FROM_QBUS (SCSIBus,qbus_create (&scsi_bus_info, host,NULL )); +qbus_create_inplace (&bus->qbus, &scsi_bus_info, host,NULL ); bus->busnr = next_scsi_bus++; bus->tcq = tcq; bus->ndev = ndev; bus->complete = complete; -return bus; }static int scsi_qdev_init (DeviceState *qdev,DeviceInfo *base)
hw/scsi-disk.h +2 -2
@@ -52,8 +52,8 @@ struct SCSIBus {SCSIDevice *devs[8 ]; }; -SCSIBus *scsi_bus_new (DeviceState *host,int tcq,int ndev, -scsi_completionfn complete); +void scsi_bus_new (SCSIBus *bus,DeviceState *host,int tcq,int ndev, +scsi_completionfn complete);void scsi_qdev_register (SCSIDeviceInfo *info);static inline SCSIBus *scsi_bus_from_device (SCSIDevice *d)
hw/usb-msd.c +3 -3
@@ -45,7 +45,7 @@ typedef struct {uint32_t data_len;uint32_t residue;uint32_t tag; -SCSIBus *bus; +SCSIBus bus;DriveInfo *dinfo;SCSIDevice *scsi_dev;int result;
@@ -527,8 +527,8 @@ static int usb_msd_initfn(USBDevice *dev) } s->dev.speed =USB_SPEED_FULL ; - s->bus =scsi_bus_new (&s->dev.qdev,0 ,1 , usb_msd_command_complete); - s->scsi_dev =scsi_bus_legacy_add_drive (s->bus, s->dinfo,0 ); +scsi_bus_new (&s->bus, &s->dev.qdev,0 ,1 , usb_msd_command_complete); + s->scsi_dev =scsi_bus_legacy_add_drive (&s->bus, s->dinfo,0 );usb_msd_handle_reset (dev);return 0 ; }
Signature · 1 line
1.6.2.5
PATCH 3/13 switch usb bus to inplace allocation.
In reply to Gerd Hoffmann--- hw/usb-bus.c | 7 ++----- hw/usb-musb.c | 6 +++--- hw/usb-ohci.c | 6 +++--- hw/usb-uhci.c | 6 +++--- hw/usb.h | 2 +- 5 files changed, 12 insertions(+), 15 deletions(-)
hw/usb-bus.c +2 -5
@@ -14,16 +14,13 @@ static struct BusInfo usb_bus_info = {static int next_usb_bus =0 ; static QTAILQ_HEAD(, USBBus) busses = QTAILQ_HEAD_INITIALIZER(busses); -USBBus *usb_bus_new (DeviceState *host) +void usb_bus_new (USBBus *bus,DeviceState *host) { -USBBus *bus; - - bus =FROM_QBUS (USBBus,qbus_create (&usb_bus_info, host,NULL )); +qbus_create_inplace (&bus->qbus, &usb_bus_info, host,NULL ); bus->busnr = next_usb_bus++;QTAILQ_INIT (&bus->free);QTAILQ_INIT (&bus->used);QTAILQ_INSERT_TAIL (&busses, bus, next); -return bus; }USBBus *usb_bus_find (int busnr)
hw/usb-musb.c +3 -3
@@ -281,7 +281,7 @@ typedef struct {struct MUSBState {qemu_irq *irqs; -USBBus *bus; +USBBus bus;USBPort port;int idx;
@@ -331,8 +331,8 @@ struct MUSBState { s->ep[i].epnum = i; } - s->bus =usb_bus_new (NULL /* FIXME */ ); -usb_register_port (s->bus, &s->port, s,0 , musb_attach); +usb_bus_new (&s->bus,NULL /* FIXME */ ); +usb_register_port (&s->bus, &s->port, s,0 , musb_attach);return s; }
hw/usb-ohci.c +3 -3
@@ -65,7 +65,7 @@ enum ohci_type { }; typedef struct { - USBBus *bus; + USBBus bus; qemu_irq irq; enum ohci_type type; int mem;
@@ -1690,10 +1690,10 @@ static void usb_ohci_init(OHCIState *ohci, DeviceState *dev, ohci->irq = irq; ohci->type = type; - ohci->bus =usb_bus_new (dev); +usb_bus_new (&ohci->bus, dev); ohci->num_ports = num_ports;for (i =0 ; i < num_ports; i++) { -usb_register_port (ohci->bus, &ohci->rhport[i].port, ohci, i, ohci_attach); +usb_register_port (&ohci->bus, &ohci->rhport[i].port, ohci, i, ohci_attach); } ohci->async_td =0 ;
hw/usb-uhci.c +3 -3
@@ -122,7 +122,7 @@ typedef struct UHCIPort { typedef struct UHCIState { PCIDevice dev; - USBBus *bus; + USBBus bus; uint16_t cmd; /* cmd register */ uint16_t status; uint16_t intr; /* interrupt enable register */
@@ -1083,9 +1083,9 @@ static int usb_uhci_common_initfn(UHCIState *s) pci_conf[0x3d ] =4 ;// interrupt pin 3 pci_conf[0x60 ] =0x10 ;// release number - s->bus =usb_bus_new (&s->dev.qdev); +usb_bus_new (&s->bus, &s->dev.qdev);for (i =0 ; i <NB_PORTS ; i++) { -usb_register_port (s->bus, &s->ports[i].port, s, i, uhci_attach); +usb_register_port (&s->bus, &s->ports[i].port, s, i, uhci_attach); } s->frame_timer =qemu_new_timer (vm_clock, uhci_frame_timer, s);
hw/usb.h +1 -1
@@ -303,7 +303,7 @@ struct USBBus {QTAILQ_ENTRY (USBBus) next; }; -USBBus *usb_bus_new (DeviceState *host); +void usb_bus_new (USBBus *bus,DeviceState *host);USBBus *usb_bus_find (int busnr);void usb_qdev_register (USBDeviceInfo *info);void usb_qdev_register_many (USBDeviceInfo *info);
Signature · 1 line
1.6.2.5
PATCH 4/13 switch ide bus to inplace allocation.
In reply to Gerd Hoffmann--- hw/ide/internal.h | 2 +- hw/ide/isa.c | 24 ++++++++++++------------ hw/ide/pci.c | 42 +++++++++++++++++++++--------------------- hw/ide/qdev.c | 7 ++----- 4 files changed, 36 insertions(+), 39 deletions(-)
hw/ide/internal.h +1 -1
@@ -551,7 +551,7 @@ void ide_init2(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1,void ide_init_ioport (IDEBus *bus,int iobase,int iobase2);/* hw/ide/qdev.c */ -IDEBus *ide_bus_new (DeviceState *dev); +void ide_bus_new (IDEBus *idebus,DeviceState *dev);IDEDevice *ide_create_drive (IDEBus *bus,int unit,DriveInfo *drive);#endif /* HW_IDE_INTERNAL_H */
hw/ide/isa.c +12 -12
@@ -37,7 +37,7 @@ typedef struct ISAIDEState { ISADevice dev; - IDEBus *bus; + IDEBus bus; uint32_t iobase; uint32_t iobase2; uint32_t isairq;
@@ -48,18 +48,18 @@ static void isa_ide_save(QEMUFile* f, void *opaque) {ISAIDEState *s = opaque; -idebus_save (f, s->bus); -ide_save (f, &s->bus->ifs[0 ]); -ide_save (f, &s->bus->ifs[1 ]); +idebus_save (f, &s->bus); +ide_save (f, &s->bus.ifs[0 ]); +ide_save (f, &s->bus.ifs[1 ]); }static int isa_ide_load (QEMUFile * f,void *opaque,int version_id) {ISAIDEState *s = opaque; -idebus_load (f, s->bus, version_id); -ide_load (f, &s->bus->ifs[0 ], version_id); -ide_load (f, &s->bus->ifs[1 ], version_id); +idebus_load (f, &s->bus, version_id); +ide_load (f, &s->bus.ifs[0 ], version_id); +ide_load (f, &s->bus.ifs[1 ], version_id);return 0 ; }
@@ -67,10 +67,10 @@ static int isa_ide_initfn(ISADevice *dev) {ISAIDEState *s =DO_UPCAST (ISAIDEState, dev, dev); - s->bus =ide_bus_new (&s->dev.qdev); -ide_init_ioport (s->bus, s->iobase, s->iobase2); +ide_bus_new (&s->bus, &s->dev.qdev); +ide_init_ioport (&s->bus, s->iobase, s->iobase2);isa_init_irq (dev, &s->irq, s->isairq); -ide_init2 (s->bus,NULL ,NULL , s->irq); +ide_init2 (&s->bus,NULL ,NULL , s->irq);register_savevm ("isa-ide" ,0 ,3 , isa_ide_save, isa_ide_load, s);return 0 ; };
@@ -90,9 +90,9 @@ int isa_ide_init(int iobase, int iobase2, int isairq, s =DO_UPCAST (ISAIDEState, dev, dev);if (hd0) -ide_create_drive (s->bus,0 , hd0); +ide_create_drive (&s->bus,0 , hd0);if (hd1) -ide_create_drive (s->bus,1 , hd1); +ide_create_drive (&s->bus,1 , hd1);return 0 ; }
hw/ide/pci.c +21 -21
100 lines not on this page · raw message
hw/ide/qdev.c +2 -5
@@ -29,12 +29,9 @@ static struct BusInfo ide_bus_info = { .size = sizeof(IDEBus), }; -IDEBus *ide_bus_new (DeviceState *dev) +void ide_bus_new (IDEBus *idebus,DeviceState *dev) { -IDEBus *idebus; - - idebus =FROM_QBUS (IDEBus,qbus_create (&ide_bus_info, dev,NULL )); -return idebus; +qbus_create_inplace (&idebus->qbus, &ide_bus_info, dev,NULL ); }static int ide_qdev_init (DeviceState *qdev,DeviceInfo *base)
Signature · 1 line
1.6.2.5
PATCH 5/13 inplace allocation for pci, split irq init.
In reply to Gerd HoffmannThis patch allows carrying the pcibus struct inplace. Separate allocation is possible as well. It also splits pci_register_bus into two parts (irq setup is separate now).
Followup patches will use this.
--- hw/pci.c | 43 +++++++++++++++++++++++++++++++++---------- hw/pci.h | 5 +++++ 2 files changed, 38 insertions(+), 10 deletions(-)
hw/pci.c +33 -10
@@ -98,24 +98,47 @@ static void pci_bus_reset(void *opaque) } } -PCIBus *pci_register_bus (DeviceState *parent,const char *name, -pci_set_irq_fn set_irq,pci_map_irq_fn map_irq, -void *irq_opaque,int devfn_min,int nirq) +void pci_bus_new_inplace (PCIBus *bus,DeviceState *parent, +const char *name,int devfn_min) { -PCIBus *bus;static int nbus =0 ; - bus =FROM_QBUS (PCIBus,qbus_create (&pci_bus_info, parent, name)); - bus->set_irq = set_irq; - bus->map_irq = map_irq; - bus->irq_opaque = irq_opaque; +qbus_create_inplace (&bus->qbus, &pci_bus_info, parent, name); bus->devfn_min = devfn_min; - bus->nirq = nirq; - bus->irq_count =qemu_mallocz (nirq *sizeof (bus->irq_count[0 ])); bus->next = first_bus; first_bus = bus;vmstate_register (nbus++, &vmstate_pcibus, bus);qemu_register_reset (pci_bus_reset, bus); +} + +PCIBus *pci_bus_new (DeviceState *parent,const char *name,int devfn_min) +{ +PCIBus *bus; + + bus =qemu_mallocz (sizeof (*bus)); + bus->qbus.qdev_allocated =1 ; +pci_bus_new_inplace (bus, parent, name, devfn_min); +return bus; +} + +void pci_bus_irqs (PCIBus *bus,pci_set_irq_fn set_irq,pci_map_irq_fn map_irq, +void *irq_opaque,int nirq) +{ + bus->set_irq = set_irq; + bus->map_irq = map_irq; + bus->irq_opaque = irq_opaque; + bus->nirq = nirq; + bus->irq_count =qemu_mallocz (nirq *sizeof (bus->irq_count[0 ])); +} + +PCIBus *pci_register_bus (DeviceState *parent,const char *name, +pci_set_irq_fn set_irq,pci_map_irq_fn map_irq, +void *irq_opaque,int devfn_min,int nirq) +{ +PCIBus *bus; + + bus =pci_bus_new (parent, name, devfn_min); +pci_bus_irqs (bus, set_irq, map_irq, irq_opaque, nirq);return bus; }
hw/pci.h +5 -0
@@ -248,6 +248,11 @@ int pci_device_load(PCIDevice *s, QEMUFile *f);typedef void (*pci_set_irq_fn )(void *opaque,int irq_num,int level);typedef int (*pci_map_irq_fn )(PCIDevice *pci_dev,int irq_num); +void pci_bus_new_inplace (PCIBus *bus,DeviceState *parent, +const char *name,int devfn_min); +PCIBus *pci_bus_new (DeviceState *parent,const char *name,int devfn_min); +void pci_bus_irqs (PCIBus *bus,pci_set_irq_fn set_irq,pci_map_irq_fn map_irq, +void *irq_opaque,int nirq);PCIBus *pci_register_bus (DeviceState *parent,const char *name,pci_set_irq_fn set_irq,pci_map_irq_fn map_irq,void *irq_opaque,int devfn_min,int nirq);
Signature · 1 line
1.6.2.5
PATCH 6/13 convert pci bridge to qdev
In reply to Gerd HoffmannAlso switch secondary pci busses to inplace allocation.
--- hw/pci.c | 66 +++++++++++++++++++++++++++++++++++++++++++++---------------- 1 files changed, 48 insertions(+), 18 deletions(-)
hw/pci.c +48 -18
@@ -142,18 +142,16 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,return bus; } -static PCIBus *pci_register_secondary_bus (PCIDevice *dev, -pci_map_irq_fn map_irq, -const char *name) +static void pci_register_secondary_bus (PCIBus *bus, +PCIDevice *dev, +pci_map_irq_fn map_irq, +const char *name) { -PCIBus *bus; - - bus =FROM_QBUS (PCIBus,qbus_create (&pci_bus_info, &dev->qdev, name)); +qbus_create_inplace (&bus->qbus, &pci_bus_info, &dev->qdev, name); bus->map_irq = map_irq; bus->parent_dev = dev; bus->next = dev->bus->next; dev->bus->next = bus; -return bus; }int pci_bus_num (PCIBus *s)
@@ -858,7 +856,9 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,typedef struct {PCIDevice dev; -PCIBus *bus; +PCIBus bus; +uint32_t vid; +uint32_t did; }PCIBridge ; static void pci_bridge_write_config(PCIDevice *d,
@@ -867,7 +867,7 @@ static void pci_bridge_write_config(PCIDevice *d,PCIBridge *s = (PCIBridge *)d;pci_default_write_config (d, address, val, len); - s->bus->bus_num = d->config[PCI_SECONDARY_BUS ]; + s->bus.bus_num = d->config[PCI_SECONDARY_BUS ]; }PCIBus *pci_find_bus (int bus_num)
@@ -890,15 +890,12 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function)return bus->devices[PCI_DEVFN (slot, function)]; } -PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint16_t vid,uint16_t did, -pci_map_irq_fn map_irq,const char *name) +static int pci_bridge_initfn (PCIDevice *dev) { -PCIBridge *s; - s = (PCIBridge *)pci_register_device (bus, name,sizeof (PCIBridge), - devfn,NULL , pci_bridge_write_config); +PCIBridge *s =DO_UPCAST (PCIBridge, dev, dev); -pci_config_set_vendor_id (s->dev.config, vid); -pci_config_set_device_id (s->dev.config, did); +pci_config_set_vendor_id (s->dev.config, s->vid); +pci_config_set_device_id (s->dev.config, s->did); s->dev.config[0x04 ] =0x06 ;// command = bus master, pci mem s->dev.config[0x05 ] =0x00 ;
@@ -911,9 +908,23 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, s->dev.config[PCI_HEADER_TYPE ] =PCI_HEADER_TYPE_MULTI_FUNCTION |PCI_HEADER_TYPE_BRIDGE ;// header_type s->dev.config[0x1E ] =0xa0 ;// secondary status +return 0 ; +} - s->bus =pci_register_secondary_bus (&s->dev, map_irq, name); -return s->bus; +PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint16_t vid,uint16_t did, +pci_map_irq_fn map_irq,const char *name) +{ +PCIDevice *dev; +PCIBridge *s; + + dev =pci_create_noinit (bus, devfn,"pci-bridge" ); +qdev_prop_set_uint32 (&dev->qdev,"vendorid" , vid); +qdev_prop_set_uint32 (&dev->qdev,"deviceid" , did); +qdev_init (&dev->qdev); + + s =DO_UPCAST (PCIBridge, dev, dev); +pci_register_secondary_bus (&s->bus, &s->dev, map_irq, name); +return &s->bus; }static int pci_qdev_init (DeviceState *qdev,DeviceInfo *base)
@@ -1074,3 +1085,22 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) r->addr, r->addr + r->size - 1); } } + +static PCIDeviceInfo bridge_info = { + .qdev.name ="pci-bridge" , + .qdev.size =sizeof (PCIBridge), + .init = pci_bridge_initfn, + .config_write = pci_bridge_write_config, + .qdev.props = (Property []) { +DEFINE_PROP_HEX32 ("vendorid" , PCIBridge, vid,0 ), +DEFINE_PROP_HEX32 ("deviceid" , PCIBridge, did,0 ), +DEFINE_PROP_END_OF_LIST (), + } +}; + +static void pci_register_devices (void ) +{ +pci_qdev_register (&bridge_info); +} + +device_init (pci_register_devices)
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 06/13] convert pci bridge to qdev
hw/pci.c PCIDevice *pci_find_device(int bus_num, int slot, int function) · line 893
Quoted 7 lines · Gerd Hoffmann
hw/pci.c +1
-2@@ -890,15 +890,12 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function)return bus->devices[PCI_DEVFN (slot, function)]; } -PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint16_t vid,uint16_t did, -pci_map_irq_fn map_irq,const char *name) +static int pci_bridge_initfn (PCIDevice *dev)
pci_bridge_dev_init a better name?
Quoted 66 lines
hw/pci.c +38
-7{ -PCIBridge *s; - s = (PCIBridge *)pci_register_device (bus, name,sizeof (PCIBridge), - devfn,NULL , pci_bridge_write_config); +PCIBridge *s =DO_UPCAST (PCIBridge, dev, dev); -pci_config_set_vendor_id (s->dev.config, vid); -pci_config_set_device_id (s->dev.config, did); +pci_config_set_vendor_id (s->dev.config, s->vid); +pci_config_set_device_id (s->dev.config, s->did); s->dev.config[0x04 ] =0x06 ;// command = bus master, pci mem s->dev.config[0x05 ] =0x00 ;@@ -911,9 +908,23 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, s->dev.config[PCI_HEADER_TYPE ] =PCI_HEADER_TYPE_MULTI_FUNCTION |PCI_HEADER_TYPE_BRIDGE ;// header_type s->dev.config[0x1E ] =0xa0 ;// secondary status +return 0 ; +} - s->bus =pci_register_secondary_bus (&s->dev, map_irq, name); -return s->bus; +PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint16_t vid,uint16_t did, +pci_map_irq_fn map_irq,const char *name) +{ +PCIDevice *dev; +PCIBridge *s; + + dev =pci_create_noinit (bus, devfn,"pci-bridge" ); +qdev_prop_set_uint32 (&dev->qdev,"vendorid" , vid); +qdev_prop_set_uint32 (&dev->qdev,"deviceid" , did); +qdev_init (&dev->qdev); + + s =DO_UPCAST (PCIBridge, dev, dev); +pci_register_secondary_bus (&s->bus, &s->dev, map_irq, name); +return &s->bus; }static int pci_qdev_init (DeviceState *qdev,DeviceInfo *base)@@ -1074,3 +1085,22 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) r->addr, r->addr + r->size - 1); } } + +static PCIDeviceInfo bridge_info = { + .qdev.name ="pci-bridge" , + .qdev.size =sizeof (PCIBridge), + .init = pci_bridge_initfn, + .config_write = pci_bridge_write_config, + .qdev.props = (Property []) { +DEFINE_PROP_HEX32 ("vendorid" , PCIBridge, vid,0 ), +DEFINE_PROP_HEX32 ("deviceid" , PCIBridge, did,0 ), +DEFINE_PROP_END_OF_LIST (), + } +}; + +static void pci_register_devices (void ) +{ +pci_qdev_register (&bridge_info); +} + +device_init (pci_register_devices)Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 06/13] convert pci bridge to qdev
Quoted 10 lines · Michael S. Tsirkin
hw/pci.c PCIDevice *pci_find_device(int bus_num, int slot, int function) · line 893
Quoted 7 lines · Gerd Hoffmann
hw/pci.c +1
-2@@ -890,15 +890,12 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function)return bus->devices[PCI_DEVFN (slot, function)]; } -PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint16_t vid,uint16_t did, -pci_map_irq_fn map_irq,const char *name) +static int pci_bridge_initfn (PCIDevice *dev)
pci_bridge_dev_inita better name?
There's precedence for _initfn, _init1, and _init. I wish we'd pick one convention and stick to it.
[...]
Re: [Qemu-devel] [PATCH 06/13] convert pci bridge to qdev
Quoted 7 lines · Markus Armbruster
Quoted 5 lines · Michael S. Tsirkin
Quoted 4 lines · Gerd Hoffmann
hw/pci.c +0
-0@@ -890,15 +890,12 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function)return bus->devices[PCI_DEVFN (slot, function)]; }
Quoted 8 lines
Quoted 5 lines
hw/pci.c PCIDevice *pci_find_device(int bus_num, int slot, int function) · line 893
Quoted 3 lines
hw/pci.c +1
-2-PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint16_t vid,uint16_t did, -pci_map_irq_fn map_irq,const char *name) +static int pci_bridge_initfn (PCIDevice *dev)
pci_bridge_dev_inita better name?There's precedence for
_initfn,_init1, and_init. I wish we'd pick one convention and stick to it.
The problem here is that we now have *both* pci_bridge_init and pci_bridge_initfn.
Quoted 1 line
[...]
Re: [Qemu-devel] [PATCH 06/13] convert pci bridge to qdev
Quoted 14 lines · Michael S. Tsirkin
Quoted 13 lines · Markus Armbruster
Quoted 10 lines · Michael S. Tsirkin
hw/pci.c PCIDevice *pci_find_device(int bus_num, int slot, int function) · line 893
Quoted 7 lines · Gerd Hoffmann
hw/pci.c +1
-2@@ -890,15 +890,12 @@ PCIDevice *pci_find_device(int bus_num, int slot, int function)return bus->devices[PCI_DEVFN (slot, function)]; } -PCIBus *pci_bridge_init (PCIBus *bus,int devfn,uint16_t vid,uint16_t did, -pci_map_irq_fn map_irq,const char *name) +static int pci_bridge_initfn (PCIDevice *dev)
pci_bridge_dev_inita better name?
Quoted 7 lines
Quoted 2 lines
There's precedence for
_initfn,_init1, and_init. I wish we'd pick one convention and stick to it.The problem here is that we now have *both*
pci_bridge_initandpci_bridge_initfn.Quoted 1 line
[...]
There are quite a few places which are simliar named. *_initfn is the qdev init callback, *_init is the convenience wrapper to keep the old code paths working, which ideally just does qdev_create() + set properties + qdev_init(). We are not there (yet) in all cases though.
cheers,
Gerd
PATCH 7/13 piix_pci: kill PIIX3IrqState
In reply to Gerd HoffmannThe splitted init + irq setup for the pci bus untangles a initialization order issue and allows to remove the PIIX3IrqState struct. We can carry the state directly in PIIX3State insted.
--- hw/piix_pci.c | 37 +++++++++++++++++-------------------- 1 files changed, 17 insertions(+), 20 deletions(-)
hw/piix_pci.c +17 -20
@@ -36,18 +36,14 @@ typedef PCIHostState I440FXState;typedef struct PIIX3State {PCIDevice dev;int pci_irq_levels[4 ]; -}PIIX3State ; - -typedef struct PIIX3IrqState { -PIIX3State *piix3;qemu_irq *pic; -}PIIX3IrqState ; +}PIIX3State ;struct PCII440FXState {PCIDevice dev;target_phys_addr_t isa_page_descs[384 /4 ];uint8_t smm_enabled; -PIIX3IrqState *irq_state; +PIIX3State *piix3; };static void i440fx_addr_writel (void * opaque,uint32_t addr,uint32_t val)
@@ -167,7 +163,7 @@ static int i440fx_load_old(QEMUFile* f, void *opaque, int version_id)if (version_id ==2 )for (i =0 ; i <4 ; i++) - d->irq_state->piix3->pci_irq_levels[i] =qemu_get_be32 (f); + d->piix3->pci_irq_levels[i] =qemu_get_be32 (f);return 0 ; }
@@ -232,23 +228,24 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *PCIBus *b;PCIDevice *d;I440FXState *s; -PIIX3IrqState *irq_state =qemu_malloc (sizeof (*irq_state)); +PIIX3State *piix3; - irq_state->pic = pic; dev =qdev_create (NULL ,"i440FX-pcihost" ); s =FROM_SYSBUS (I440FXState,sysbus_from_qdev (dev)); - b =pci_register_bus (&s->busdev.qdev,"pci.0" , - piix3_set_irq, pci_slot_get_pirq, irq_state,0 ,4 ); + b =pci_bus_new (&s->busdev.qdev,NULL ,0 ); s->bus = b;qdev_init (dev); d =pci_create_simple (b,0 ,"i440FX" ); *pi440fx_state =DO_UPCAST (PCII440FXState, dev, d); - (*pi440fx_state)->irq_state = irq_state; - irq_state->piix3 =DO_UPCAST (PIIX3State, dev, + piix3 =DO_UPCAST (PIIX3State, dev,pci_create_simple (b,-1 ,"PIIX3" )); - *piix3_devfn = irq_state->piix3->dev.devfn; + piix3->pic = pic; +pci_bus_irqs (b, piix3_set_irq, pci_slot_get_pirq, piix3,4 ); + (*pi440fx_state)->piix3 = piix3; + + *piix3_devfn = piix3->dev.devfn;return b; }
@@ -258,22 +255,22 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *static void piix3_set_irq (void *opaque,int irq_num,int level) {int i, pic_irq, pic_level; -PIIX3IrqState *irq_state = opaque; +PIIX3State *piix3 = opaque; - irq_state->piix3->pci_irq_levels[irq_num] = level; + piix3->pci_irq_levels[irq_num] = level;/* now we change the pic irq level according to the piix irq mappings */ /* XXX: optimize */ - pic_irq = irq_state->piix3->dev.config[0x60 + irq_num]; + pic_irq = piix3->dev.config[0x60 + irq_num];if (pic_irq <16 ) {/* The pic level is the logical OR of all the PCI irqs mapped to it */ pic_level =0 ;for (i =0 ; i <4 ; i++) { -if (pic_irq == irq_state->piix3->dev.config[0x60 + i]) - pic_level |= irq_state->piix3->pci_irq_levels[i]; +if (pic_irq == piix3->dev.config[0x60 + i]) + pic_level |= piix3->pci_irq_levels[i]; } -qemu_set_irq (irq_state->pic[pic_irq], pic_level); +qemu_set_irq (piix3->pic[pic_irq], pic_level); } }
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 07/13] piix_pci: kill PIIX3IrqState
Quoted 13 lines · Gerd Hoffmann
The splitted init + irq setup for the pci bus untangles a initialization order issue and allows to remove the PIIX3IrqState struct. We can carry the state directly in PIIX3State insted.
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/piix_pci.c | 37 +++++++++++++++++-------------------- 1 files changed, 17 insertions(+), 20 deletions(-)hw/piix_pci.c +0
-0
[...]
hw/piix_pci.c PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq * · line 235
Quoted 13 lines
hw/piix_pci.c +2
-4@@ -232,23 +228,24 @@ PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq *PCIBus *b;PCIDevice *d;I440FXState *s; -PIIX3IrqState *irq_state =qemu_malloc (sizeof (*irq_state)); +PIIX3State *piix3; - irq_state->pic = pic; dev =qdev_create (NULL ,"i440FX-pcihost" ); s =FROM_SYSBUS (I440FXState,sysbus_from_qdev (dev)); - b =pci_register_bus (&s->busdev.qdev,"pci.0" , - piix3_set_irq, pci_slot_get_pirq, irq_state,0 ,4 ); + b =pci_bus_new (&s->busdev.qdev,NULL ,0 );
Passes null name to pci_bus_new(). Intentional? Before, we passed "pci.0" to pci_register_bus().
Quoted 19 lines
hw/piix_pci.c +6
-3s->bus = b;qdev_init (dev); d =pci_create_simple (b,0 ,"i440FX" ); *pi440fx_state =DO_UPCAST (PCII440FXState, dev, d); - (*pi440fx_state)->irq_state = irq_state; - irq_state->piix3 =DO_UPCAST (PIIX3State, dev, + piix3 =DO_UPCAST (PIIX3State, dev,pci_create_simple (b,-1 ,"PIIX3" )); - *piix3_devfn = irq_state->piix3->dev.devfn; + piix3->pic = pic; +pci_bus_irqs (b, piix3_set_irq, pci_slot_get_pirq, piix3,4 ); + (*pi440fx_state)->piix3 = piix3; + + *piix3_devfn = piix3->dev.devfn;return b; }
[...]
Re: [Qemu-devel] [PATCH 07/13] piix_pci: kill PIIX3IrqState
Hi,
Quoted 6 lines
hw/piix_pci.c PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix3_devfn, qemu_irq * · line 235
Quoted 3 lines
hw/piix_pci.c +1
-2- b =pci_register_bus (&s->busdev.qdev,"pci.0" , - piix3_set_irq, pci_slot_get_pirq, irq_state,0 ,4 ); + b =pci_bus_new (&s->busdev.qdev,NULL ,0 );Passes null name to
pci_bus_new(). Intentional? Before, we passed "pci.0" topci_register_bus().
Yes. qbus_create() will construct a name for you, which happens to be "pci.0". So we don't need to pass it in. Having "pci.0" in there was just temporary needed due to the order patches where merged.
cheers,
Gerd
PATCH 8/13 qdev: device free fixups.
In reply to Gerd HoffmannTwo bug fixes:
* When freeing a device we unregister stuff unconditionally, even in case we didn't register in the first place because the ->init() callback failed.
* When freeing a device with child busses attached we don't zap the child bus (and the devices attached to it).
--- hw/qdev.c | 35 +++++++++++++++++++++++++++++++---- hw/qdev.h | 7 +++++++ 2 files changed, 38 insertions(+), 4 deletions(-)
hw/qdev.c +31 -4
@@ -102,6 +102,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)qdev_prop_set_defaults (dev, dev->parent_bus->info->props);qdev_prop_set_compat (dev);QLIST_INSERT_HEAD (&bus->children, dev, sibling); + dev->state =DEV_STATE_CREATED ;return dev; }
@@ -216,6 +217,7 @@ int qdev_init(DeviceState *dev) {int rc; +assert (dev->state ==DEV_STATE_CREATED ); rc = dev->info->init (dev, dev->info);if (rc <0 )return rc;
@@ -223,18 +225,27 @@ int qdev_init(DeviceState *dev)qemu_register_reset (dev->info->reset, dev);if (dev->info->vmsd)vmstate_register (-1 , dev->info->vmsd, dev); + dev->state =DEV_STATE_INITIALIZED ;return 0 ; }/* Unlink device from bus and free the structure. */ void qdev_free (DeviceState *dev) { +BusState *bus; + +if (dev->state ==DEV_STATE_INITIALIZED ) { +while (dev->num_child_bus) { + bus =QLIST_FIRST (&dev->child_bus); +qbus_free (bus); + }#if 0 /* FIXME: need sane vmstate_unregister function */ -if (dev->info->vmsd) -vmstate_unregister (dev->info->vmsd, 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->reset) +qemu_unregister_reset (dev->info->reset, dev); + }QLIST_REMOVE (dev, sibling);qemu_free (dev); }
@@ -549,6 +560,22 @@ BusState *qbus_create(BusInfo *info, DeviceState *parent, const char *name)return bus; } +void qbus_free (BusState *bus) +{ +DeviceState *dev; + +while ((dev =QLIST_FIRST (&bus->children)) !=NULL ) { +qdev_free (dev); + } +if (bus->parent) { +QLIST_REMOVE (bus, sibling); + bus->parent->num_child_bus--; + } +if (bus->qdev_allocated) { +qemu_free (bus); + } +} +#define qdev_printf (fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)static void qbus_print (Monitor *mon,BusState *bus,int indent);
hw/qdev.h +7 -0
@@ -19,10 +19,16 @@ typedef struct BusState BusState;typedef struct BusInfo BusInfo ; +enum DevState { +DEV_STATE_CREATED =1 , +DEV_STATE_INITIALIZED , +}; +/* This structure should not be accessed directly. We declare it here so that it can be embedded in individual device state structures. */ struct DeviceState {const char *id; +enum DevState state;DeviceInfo *info;BusState *parent_bus;int num_gpio_out;
@@ -148,6 +154,7 @@ BusState *qdev_get_parent_bus(DeviceState *dev);void qbus_create_inplace (BusState *bus,BusInfo *info,DeviceState *parent,const char *name);BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name); +void qbus_free (BusState *bus);#define FROM_QBUS (type, dev) DO_UPCAST(type, qbus, dev)
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 08/13] qdev: device free fixups.
Quoted 8 lines · Gerd Hoffmann
Two bug fixes:
* When freeing a device we unregister stuff unconditionally, even in case we didn't register in the first place because the ->init() callback failed.
* When freeing a device with child busses attached we don't zap the child bus (and the devices attached to it).Signed-off-by Gerd Hoffmann <[email protected]>
Maybe I'm just having a particularly dense day, but I misread this as "this is what the fix does". In reality, it's "this is what we did wrong". Careless readers like me can be kept on track by emphasizing the "wrongness" of what's being done, so that it's (more) obvious we're talking about the bug and not the fix:
* When freeing a device we unregister even stuff we didn't register in
the first place because the ->init() callback failed.
* When freeing a device with child busses attached, we fail to zap the child bus (and the devices attached to it).
Another language trick is to use past tense for the bug and present tense for the fix.
PATCH 9/13 Add exit callback to DeviceInfo.
In reply to Gerd HoffmannThis adds a exit callback for device destruction to DeviceInfo, so we can hook cleanups into qdev device destruction.
Followup patches will put that into use.
--- hw/qdev.c | 2 ++ hw/qdev.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)
hw/qdev.c +2 -0
@@ -245,6 +245,8 @@ void qdev_free(DeviceState *dev)#endif if (dev->info->reset)qemu_unregister_reset (dev->info->reset, dev); +if (dev->info->exit) + dev->info->exit (dev); }QLIST_REMOVE (dev, sibling);qemu_free (dev);
hw/qdev.h +2 -0
@@ -107,6 +107,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name);/*** Device API. ***/ typedef int (*qdev_initfn )(DeviceState *dev,DeviceInfo *info); +typedef int (*qdev_exitfn )(DeviceState *dev);struct DeviceInfo {const char *name;
@@ -124,6 +125,7 @@ struct DeviceInfo {/* Private to qdev / bus. */ qdev_initfn init; +qdev_exitfn exit;BusInfo *bus_info;struct DeviceInfo *next; };
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 09/13] Add exit callback to DeviceInfo.
Quoted 2 lines · On Tuesday 22 September 2009 11:29:23 Gerd Hoffmann wrote:
This adds a exit callback for device destruction to DeviceInfo, so we can hook cleanups into qdev device destruction.
This is not enough.
You need a childexit to allow devices to cleanup their children in the device tree first.
Christoph
Quoted 42 lines
Followup patches will put that into use.
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/qdev.c | 2 ++ hw/qdev.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)hw/qdev.c +2
-0@@ -245,6 +245,8 @@ void qdev_free(DeviceState *dev)#endif if (dev->info->reset)qemu_unregister_reset (dev->info->reset, dev); +if (dev->info->exit) + dev->info->exit (dev); }QLIST_REMOVE (dev, sibling);qemu_free (dev);hw/qdev.h +0
-0@@ -107,6 +107,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, constchar *name); /*** Device API. ***/
typedef int (*qdev_initfn)(DeviceState *dev, DeviceInfo *info);
hw/qdev.h +2
-0+typedef int (*qdev_exitfn )(DeviceState *dev);struct DeviceInfo {const char *name;@@ -124,6 +125,7 @@ struct DeviceInfo {/* Private to qdev / bus. */ qdev_initfn init; +qdev_exitfn exit;BusInfo *bus_info;struct DeviceInfo *next; };
Signature · 6 lines
---to satisfy European Law for business letters: Advanced Micro Devices GmbH Karl-Hammerschmidt-Str. 34, 85609 Dornach b. Muenchen Geschaeftsfuehrer: Andrew Bowd, Thomas M. McCoy, Giuliano Meroni Sitz: Dornach, Gemeinde Aschheim, Landkreis Muenchen Registergericht Muenchen, HRB Nr. 43632
Re: [Qemu-devel] [PATCH 09/13] Add exit callback to DeviceInfo.
Quoted 7 lines · Christoph Egger
Quoted 2 lines · On Tuesday 22 September 2009 11:29:23 Gerd Hoffmann wrote:
This adds a exit callback for device destruction to DeviceInfo, so we can hook cleanups into qdev device destruction.
This is not enough.
You need a childexit to allow devices to cleanup their children in the device tree first.
qdev will do that for you. Check out patch #8 and the new qbus_free() function added there.
Of course the bus implementations must make use of the exit hook so it actually works, the following patches do that for pci, scsi and usb.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 09/13] Add exit callback to DeviceInfo.
In reply to Gerd HoffmannQuoted 37 lines · Gerd Hoffmann
This adds a exit callback for device destruction to DeviceInfo, so we can hook cleanups into qdev device destruction.
Followup patches will put that into use.
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/qdev.c | 2 ++ hw/qdev.h | 2 ++ 2 files changed, 4 insertions(+), 0 deletions(-)hw/qdev.c +2
-0@@ -245,6 +245,8 @@ void qdev_free(DeviceState *dev)#endif if (dev->info->reset)qemu_unregister_reset (dev->info->reset, dev); +if (dev->info->exit) + dev->info->exit (dev); }QLIST_REMOVE (dev, sibling);qemu_free (dev);hw/qdev.h +1
-0@@ -107,6 +107,7 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name);/*** Device API. ***/ typedef int (*qdev_initfn )(DeviceState *dev,DeviceInfo *info); +typedef int (*qdev_exitfn )(DeviceState *dev);struct DeviceInfo {const char *name;
hw/qdev.h struct DeviceInfo { · line 131
Quoted 7 lines
hw/qdev.h +1
-0@@ -124,6 +125,7 @@ struct DeviceInfo {/* Private to qdev / bus. */ qdev_initfn init; +qdev_exitfn exit;BusInfo *bus_info;struct DeviceInfo *next; };
I don't like the name "exit". The buddy of init() is often called fini().
Re: [Qemu-devel] [PATCH 09/13] Add exit callback to DeviceInfo.
Quoted 8 lines
Quoted 5 lines
qdev_initfn init; + qdev_exitfn exit; BusInfo *bus_info; struct DeviceInfo *next;};
I don't like the name "exit". The buddy of
init()is often calledfini().
Picked that name convention up from the linux kernel which has module_init() and module_exit() ...
I can change it, but I'd like to have some kind of agreement on the list so I don't have to go through all the patches changing this twice. Naming variants I can thing of are:
* exit
* fini
* free
* uninit
* cleanup
* release
Comments?
cheers,
Gerd
PATCH 10/13 Implement scsi device destruction
In reply to Gerd Hoffmann--- hw/scsi-bus.c | 24 +++++++++++++++++++++--- hw/scsi-disk.c | 6 ------ hw/scsi-generic.c | 2 -- 3 files changed, 21 insertions(+), 11 deletions(-)
hw/scsi-bus.c +21 -3
@@ -30,6 +30,7 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)SCSIDevice *dev =DO_UPCAST (SCSIDevice, qdev, qdev);SCSIDeviceInfo *info =DO_UPCAST (SCSIDeviceInfo, qdev, base);SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); +int rc =-1 ;if (dev->id ==-1 ) {for (dev->id =0 ; dev->id < bus->ndev; dev->id++) {
@@ -43,21 +44,38 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) }if (bus->devs[dev->id]) { - bus->devs[dev->id]->info->destroy (bus->devs[dev->id]); +qdev_free (&bus->devs[dev->id]->qdev); } bus->devs[dev->id] = dev; dev->info = info; -return dev->info->init (dev); + rc = dev->info->init (dev); +if (rc !=0 ) { + bus->devs[dev->id] =NULL ; + } err: -return -1 ; +return rc; +} + +static int scsi_qdev_exit (DeviceState *qdev) +{ +SCSIDevice *dev =DO_UPCAST (SCSIDevice, qdev, qdev); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); + +assert (bus->devs[dev->id] !=NULL ); +if (bus->devs[dev->id]->info->destroy) { + bus->devs[dev->id]->info->destroy (bus->devs[dev->id]); + } + bus->devs[dev->id] =NULL ; +return 0 ; }void scsi_qdev_register (SCSIDeviceInfo *info) { info->qdev.bus_info = &scsi_bus_info; info->qdev.init = scsi_qdev_init; + info->qdev.exit = scsi_qdev_exit;qdev_register (&info->qdev); }
hw/scsi-disk.c +0 -6
@@ -936,11 +936,6 @@ static int32_t scsi_send_command(SCSIDevice *d, uint32_t tag, } } -static void scsi_destroy (SCSIDevice *d) -{ -qemu_free (d); -} -static int scsi_disk_initfn (SCSIDevice *dev) {SCSIDiskState *s =DO_UPCAST (SCSIDiskState, qdev, dev);
@@ -974,7 +969,6 @@ static SCSIDeviceInfo scsi_disk_info = { .qdev.desc = "virtual scsi disk or cdrom", .qdev.size = sizeof(SCSIDiskState), .init = scsi_disk_initfn, - .destroy = scsi_destroy, .send_command = scsi_send_command, .read_data = scsi_read_data, .write_data = scsi_write_data,
hw/scsi-generic.c +0 -2
@@ -668,8 +668,6 @@ static void scsi_destroy(SCSIDevice *d)qemu_free (r); r = n; } - -qemu_free (d); }static int scsi_generic_initfn (SCSIDevice *dev)
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction
Quoted 20 lines · Gerd Hoffmann
Signed-off-by Gerd Hoffmann <[email protected]>--- hw/scsi-bus.c | 24 +++++++++++++++++++++--- hw/scsi-disk.c | 6 ------ hw/scsi-generic.c | 2 -- 3 files changed, 21 insertions(+), 11 deletions(-)hw/scsi-bus.c +1
-0@@ -30,6 +30,7 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base)SCSIDevice *dev =DO_UPCAST (SCSIDevice, qdev, qdev);SCSIDeviceInfo *info =DO_UPCAST (SCSIDeviceInfo, qdev, base);SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); +int rc =-1 ;if (dev->id ==-1 ) {for (dev->id =0 ; dev->id < bus->ndev; dev->id++) {
hw/scsi-bus.c static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) · line 48
Quoted 6 lines
hw/scsi-bus.c +1
-1@@ -43,21 +44,38 @@ static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) }if (bus->devs[dev->id]) { - bus->devs[dev->id]->info->destroy (bus->devs[dev->id]); +qdev_free (&bus->devs[dev->id]->qdev); }
If I understand this correctly, SCSI devices "overwrite": if you add a new one with an existing SCSI ID, the old one gets disconnected automatically. Isn't that inconsistent with other buses? PCI, specifically. Question applies before your patch already.
Quoted 16 lines
hw/scsi-bus.c +9
-2bus->devs[dev->id] = dev; dev->info = info; -return dev->info->init (dev); + rc = dev->info->init (dev); +if (rc !=0 ) { + bus->devs[dev->id] =NULL ; + } err: -return -1 ; +return rc; +} + +static int scsi_qdev_exit (DeviceState *qdev) +{
hw/scsi-bus.c static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) · line 72
Quoted 10 lines
hw/scsi-bus.c +9
-0+SCSIDevice *dev =DO_UPCAST (SCSIDevice, qdev, qdev); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); + +assert (bus->devs[dev->id] !=NULL ); +if (bus->devs[dev->id]->info->destroy) { + bus->devs[dev->id]->info->destroy (bus->devs[dev->id]); + } + bus->devs[dev->id] =NULL ; +return 0 ; }
You have scsi_qdev_exit() as qdev callback exit(). It does the generic stuff, then runs the SCSIDevice callback destroy() for the specific stuff. Shouldn't the two callbacks be named the same, to make their relation more obvious?
Quoted 9 lines
hw/scsi-bus.c +1
-0void scsi_qdev_register (SCSIDeviceInfo *info) { info->qdev.bus_info = &scsi_bus_info; info->qdev.init = scsi_qdev_init; + info->qdev.exit = scsi_qdev_exit;qdev_register (&info->qdev); }
[...]
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction
Hi,
Quoted 4 lines
If I understand this correctly, SCSI devices "overwrite": if you add a new one with an existing SCSI ID, the old one gets disconnected automatically. Isn't that inconsistent with other buses? PCI, specifically. Question applies before your patch already.
Yes, this is correct.
I've just maintained current behavior.
To extend that question: While playing with that I've noticed linux does not automagically find the a scsi disk hot-plugged in. After reboot (and the scsi bus rescan triggered by that) it finds the disk. Reloading the driver module probably would have worked too. We don't signal the guest in any way it got a new disk, so this isn't exactly surprising. Is this just a emulation limitation? Or a limitation of the emulated scsi host adapters?
Quoted 9 lines
Quoted 9 lines
hw/scsi-bus.c +9
-0+static int scsi_qdev_exit (DeviceState *qdev) +{ +SCSIDevice *dev =DO_UPCAST (SCSIDevice, qdev, qdev); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); + +assert (bus->devs[dev->id] !=NULL ); +if (bus->devs[dev->id]->info->destroy) { + bus->devs[dev->id]->info->destroy (bus->devs[dev->id]); + }
Quoted 8 lines
hw/scsi-bus.c static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) · line 72
Quoted 3 lines
hw/scsi-bus.c +2
-0+ bus->devs[dev->id] =NULL ; +return 0 ; }You have
scsi_qdev_exit()as qdev callbackexit(). It does the generic stuff, then runs the SCSIDevice callbackdestroy()for the specific stuff. Shouldn't the two callbacks be named the same, to make their relation more obvious?
I'm just using the existing callbacks and windup stuff correctly in the qdev_free() paths. Make the naming more consistent would be useful indeed, but that is IMHO a job for a separate patch. And we should agree on a naming convention first ;)
cheers,
Gerd
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
If I understand this correctly, SCSI devices "overwrite": if you add a new one with an existing SCSI ID, the old one gets disconnected automatically. Isn't that inconsistent with other buses? PCI, specifically. Question applies before your patch already.
Yes, this is correct.
I've just maintained current behavior.
Quoted 7 lines
To extend that question: While playing with that I've noticed linux does not automagically find the a scsi disk hot-plugged in. After reboot (and the scsi bus rescan triggered by that) it finds the disk. Reloading the driver module probably would have worked too. We don't signal the guest in any way it got a new disk, so this isn't exactly surprising. Is this just a emulation limitation? Or a limitation of the emulated scsi host adapters?
What appens when you hotplug or just switch on a real SCSI device? Does Linux pick it up automatically? Long ago when I last tried that, I think I had to do a magic write to sysfs to make it look for the device.
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
hw/scsi-bus.c +9
-0+static int scsi_qdev_exit (DeviceState *qdev) +{ +SCSIDevice *dev =DO_UPCAST (SCSIDevice, qdev, qdev); +SCSIBus *bus =DO_UPCAST (SCSIBus, qbus, dev->qdev.parent_bus); + +assert (bus->devs[dev->id] !=NULL ); +if (bus->devs[dev->id]->info->destroy) { + bus->devs[dev->id]->info->destroy (bus->devs[dev->id]); + }Quoted 8 lines
hw/scsi-bus.c static int scsi_qdev_init(DeviceState *qdev, DeviceInfo *base) · line 72
Quoted 3 lines
hw/scsi-bus.c +2
-0+ bus->devs[dev->id] =NULL ; +return 0 ; }You have
scsi_qdev_exit()as qdev callbackexit(). It does the generic stuff, then runs the SCSIDevice callbackdestroy()for the specific stuff. Shouldn't the two callbacks be named the same, to make their relation more obvious?
Quoted 4 lines
I'm just using the existing callbacks and windup stuff correctly in the
qdev_free()paths. Make the naming more consistent would be useful indeed, but that is IMHO a job for a separate patch. And we should agree on a naming convention first ;)
Fair enough.
Tasteful naming *is* important.
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction
Hi,
Quoted 11 lines
Quoted 7 lines
To extend that question: While playing with that I've noticed linux does not automagically find the a scsi disk hot-plugged in. After reboot (and the scsi bus rescan triggered by that) it finds the disk. Reloading the driver module probably would have worked too. We don't signal the guest in any way it got a new disk, so this isn't exactly surprising. Is this just a emulation limitation? Or a limitation of the emulated scsi host adapters?
What appens when you hotplug or just switch on a real SCSI device? Does Linux pick it up automatically? Long ago when I last tried that, I think I had to do a magic write to sysfs to make it look for the device.
Old, classic, parallel scsi (with the 50wire cable) works that way. But IIRC there are also more modern variants which can handle hotplug.
Dunno how that works though and whenever we could do that with the lsi adapter we are emulating ...
cheers,
Gerd
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction
In reply to Markus Armbruster2009/9/25 Markus Armbruster <[email protected]>:
Quoted 20 lines
Quoted 10 lines · Gerd Hoffmann
Hi,
Quoted 4 lines
If I understand this correctly, SCSI devices "overwrite": if you add a new one with an existing SCSI ID, the old one gets disconnected automatically. Isn't that inconsistent with other buses? PCI, specifically. Question applies before your patch already.
Yes, this is correct.
I've just maintained current behavior.Quoted 7 lines
To extend that question: While playing with that I've noticed linux does not automagically find the a scsi disk hot-plugged in. After reboot (and the scsi bus rescan triggered by that) it finds the disk. Reloading the driver module probably would have worked too. We don't signal the guest in any way it got a new disk, so this isn't exactly surprising. Is this just a emulation limitation? Or a limitation of the emulated scsi host adapters?
Quoted 3 lines
What appens when you hotplug or just switch on a real SCSI device? Does Linux pick it up automatically? Long ago when I last tried that, I think I had to do a magic write to sysfs to make it look for the device.
I guess it wasn't magic, but an official way of doing it. At least SCSI-2 controllers didn't get any notification signal on a hot-plug. I used to do it with
echo "scsi add-single-device 0 0 3 0" > /proc/scsi/scsi
Re: [Qemu-devel] [PATCH 10/13] Implement scsi device destruction
Quoted 2 lines · Artyom Tarasenko
2009/9/25 Markus Armbruster <[email protected]>:
Quoted 1 line
Gerd Hoffmann <[email protected]> writes:
[...]
Quoted 8 lines
Quoted 8 lines
Quoted 7 lines
To extend that question: While playing with that I've noticed linux does not automagically find the a scsi disk hot-plugged in. After reboot (and the scsi bus rescan triggered by that) it finds the disk. Reloading the driver module probably would have worked too. We don't signal the guest in any way it got a new disk, so this isn't exactly surprising. Is this just a emulation limitation? Or a limitation of the emulated scsi host adapters?
Quoted 8 lines
Quoted 3 lines
What appens when you hotplug or just switch on a real SCSI device? Does Linux pick it up automatically? Long ago when I last tried that, I think I had to do a magic write to sysfs to make it look for the device.
I guess it wasn't magic, but an official way of doing it. At least SCSI-2 controllers didn't get any notification signal on a hot-plug. I used to do it with
echo "scsi add-single-device 0 0 3 0" >/proc/scsi/scsi
Call it "official magic" then ;)
PATCH 11/13 pci: use qdev for device destruction.
In reply to Gerd Hoffmannpci_unregister_device is static now and hooked into Devicestate->exit. qdev_free(pci_device) works now.
--- hw/pci-hotplug.c | 2 +- hw/pci.c | 5 +++-- hw/pci.h | 2 -- 3 files changed, 4 insertions(+), 5 deletions(-)
hw/pci-hotplug.c +1 -1
@@ -247,6 +247,6 @@ void pci_device_hot_remove_success(int pcibus, int slot)break ; } -pci_unregister_device (d); +qdev_free (&d->qdev); }
hw/pci.c +3 -2
@@ -399,8 +399,9 @@ static void pci_unregister_io_regions(PCIDevice *pci_dev) } } -int pci_unregister_device (PCIDevice *pci_dev) +static int pci_unregister_device (DeviceState *dev) { +PCIDevice *pci_dev =DO_UPCAST (PCIDevice, qdev, dev);int ret =0 ;if (pci_dev->unregister)
@@ -412,7 +413,6 @@ int pci_unregister_device(PCIDevice *pci_dev)qemu_free_irqs (pci_dev->irq); pci_dev->bus->devices[pci_dev->devfn] =NULL ; -qdev_free (&pci_dev->qdev);return 0 ; }
@@ -945,6 +945,7 @@ static int pci_qdev_init(DeviceState *qdev, DeviceInfo *base)void pci_qdev_register (PCIDeviceInfo *info) { info->qdev.init = pci_qdev_init; + info->qdev.exit = pci_unregister_device; info->qdev.bus_info = &pci_bus_info;qdev_register (&info->qdev); }
hw/pci.h +0 -2
@@ -185,7 +185,6 @@ struct PCIDevice {/* do not access the following fields */ PCIConfigReadFunc *config_read;PCIConfigWriteFunc *config_write; -PCIUnregisterFunc *unregister;/* IRQ objects for the INTA-INTD pins. */ qemu_irq *irq;
@@ -224,7 +223,6 @@ PCIDevice *pci_register_device(PCIBus *bus, const char *name, int instance_size, int devfn, PCIConfigReadFunc *config_read, PCIConfigWriteFunc *config_write); -int pci_unregister_device (PCIDevice *pci_dev); void pci_register_bar(PCIDevice *pci_dev, int region_num, uint32_t size, int type,
Signature · 1 line
1.6.2.5
PATCH 12/13 pci: move unregister from PCIDevice to PCIDeviceInfo
In reply to Gerd HoffmannOne more cleanup while being at it ;)
--- hw/e1000.c | 2 +- hw/eepro100.c | 5 +++-- hw/lsi53c895a.c | 2 +- hw/pci.c | 7 +++++-- hw/pci.h | 1 + hw/pcnet.c | 3 +-- hw/rtl8139.c | 3 +-- hw/virtio-pci.c | 1 - 8 files changed, 13 insertions(+), 11 deletions(-)
hw/e1000.c +1 -1
@@ -1129,7 +1129,6 @@ static int pci_e1000_init(PCIDevice *pci_dev)qemu_format_nic_info_str (d->vc, macaddr);register_savevm (info_str,-1 ,2 , nic_save, nic_load, d); - d->dev.unregister = pci_e1000_uninit;qemu_register_reset (e1000_reset, d);e1000_reset (d);return 0 ;
@@ -1139,6 +1138,7 @@ static PCIDeviceInfo e1000_info = { .qdev.name = "e1000", .qdev.size = sizeof(E1000State), .init = pci_e1000_init, + .exit = pci_e1000_uninit, };static void e1000_register_devices (void )
hw/eepro100.c +3 -2
@@ -1733,8 +1733,6 @@ static int nic_init(PCIDevice *pci_dev, uint32_t device)logout ("\n" ); - s->dev.unregister = pci_nic_uninit; - s->device = device;pci_reset (s);
@@ -1793,14 +1791,17 @@ static PCIDeviceInfo eepro100_info[] = { .qdev.name = "i82551", .qdev.size = sizeof(EEPRO100State), .init = pci_i82551_init, + .exit = pci_nic_uninit, },{ .qdev.name = "i82557b", .qdev.size = sizeof(EEPRO100State), .init = pci_i82557b_init, + .exit = pci_nic_uninit, },{ .qdev.name = "i82559er", .qdev.size = sizeof(EEPRO100State), .init = pci_i82559er_init, + .exit = pci_nic_uninit, },{ /* end of list */ }
hw/lsi53c895a.c +1 -1
@@ -2174,7 +2174,6 @@ static int lsi_scsi_init(PCIDevice *dev) s->queue =qemu_malloc (sizeof (lsi_queue)); s->queue_len =1 ; s->active_commands =0 ; - s->dev.unregister = lsi_scsi_uninit;lsi_soft_reset (s);
@@ -2189,6 +2188,7 @@ static PCIDeviceInfo lsi_info = { .qdev.alias = "lsi", .qdev.size = sizeof(LSIState), .init = lsi_scsi_init, + .exit = lsi_scsi_uninit, };static void lsi53c895a_register_devices (void )
hw/pci.c +5 -2
@@ -26,6 +26,7 @@#include "monitor.h" #include "net.h" #include "sysemu.h" +#include "msix.h" //#define DEBUG_PCI #ifdef DEBUG_PCI
@@ -402,13 +403,15 @@ static void pci_unregister_io_regions(PCIDevice *pci_dev)static int pci_unregister_device (DeviceState *dev) {PCIDevice *pci_dev =DO_UPCAST (PCIDevice, qdev, dev); +PCIDeviceInfo *info =DO_UPCAST (PCIDeviceInfo, qdev, dev->info);int ret =0 ; -if (pci_dev->unregister) - ret = pci_dev->unregister (pci_dev); +if (info->exit) + ret = info->exit (pci_dev);if (ret)return ret; +msix_uninit (pci_dev);pci_unregister_io_regions (pci_dev);qemu_free_irqs (pci_dev->irq);
hw/pci.h +1 -0
@@ -329,6 +329,7 @@ typedef int (*pci_qdev_initfn)(PCIDevice *dev);typedef struct {DeviceInfo qdev;pci_qdev_initfn init; +PCIUnregisterFunc *exit;PCIConfigReadFunc *config_read;PCIConfigWriteFunc *config_write; }PCIDeviceInfo ;
hw/pcnet.c +1 -2
@@ -2039,8 +2039,6 @@ static int pci_pcnet_init(PCIDevice *pci_dev) sizeof(struct pcnet_RMD), sizeof(struct pcnet_TMD));#endif - pci_dev->unregister = pci_pcnet_uninit; - pci_conf = pci_dev->config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_AMD );
@@ -2170,6 +2168,7 @@ static PCIDeviceInfo pcnet_info = { .qdev.name = "pcnet", .qdev.size = sizeof(PCIPCNetState), .init = pci_pcnet_init, + .exit = pci_pcnet_uninit, };static void pcnet_register_devices (void )
hw/rtl8139.c +1 -2
@@ -3443,8 +3443,6 @@ static int pci_rtl8139_init(PCIDevice *dev)RTL8139State * s =DO_UPCAST (RTL8139State, dev, dev);uint8_t *pci_conf; - s->dev.unregister = pci_rtl8139_uninit; - pci_conf = s->dev.config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_REALTEK );pci_config_set_device_id (pci_conf,PCI_DEVICE_ID_REALTEK_8139 );
@@ -3493,6 +3491,7 @@ static PCIDeviceInfo rtl8139_info = { .qdev.size = sizeof(RTL8139State), .qdev.reset = rtl8139_reset, .init = pci_rtl8139_init, + .exit = pci_rtl8139_uninit, };static void rtl8139_register_devices (void )
hw/virtio-pci.c +0 -1
@@ -417,7 +417,6 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev,msix_bar_size (&proxy->pci_dev),PCI_ADDRESS_SPACE_MEM , msix_mmio_map); - proxy->pci_dev.unregister = msix_uninit; }else vdev->nvectors =0 ;
Signature · 1 line
1.6.2.5
Re: [Qemu-devel] [PATCH 12/13] pci: move unregister from PCIDevice to PCIDeviceInfo
Quoted 20 lines · Gerd Hoffmann
hw/pci.c +2
-1@@ -26,6 +26,7 @@#include "monitor.h" #include "net.h" #include "sysemu.h" +#include "msix.h" //#define DEBUG_PCI #ifdef DEBUG_PCI @@ -402,13 +403,15 @@ static void pci_unregister_io_regions(PCIDevice *pci_dev)static int pci_unregister_device (DeviceState *dev) {PCIDevice *pci_dev =DO_UPCAST (PCIDevice, qdev, dev); +PCIDeviceInfo *info =DO_UPCAST (PCIDeviceInfo, qdev, dev->info);int ret =0 ; -if (pci_dev->unregister)
hw/pci.c static void pci_unregister_io_regions(PCIDevice *pci_dev) · line 417
Quoted 10 lines
hw/pci.c +3
-1- ret = pci_dev->unregister (pci_dev); +if (info->exit) + ret = info->exit (pci_dev);if (ret)return ret; +msix_uninit (pci_dev);pci_unregister_io_regions (pci_dev);qemu_free_irqs (pci_dev->irq);
Since devices call msix_add, I think it is cleaner to have them uninit it as well in their exit routines.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH 12/13] pci: move unregister from PCIDevice to PCIDeviceInfo
Hi,
Quoted 6 lines
Quoted 3 lines
static int
pci_unregister_device(DeviceState *dev)+
msix_uninit(pci_dev);Since devices call
msix_add, I think it is cleaner to have them uninit it as well in their exit routines.
Would work too. But this way you can't miss the msix_uninit() call by accident. It also saves a few lines of code. msix_uninit() carefully checks whenever msix is actually enabled and it is slow path, so calling it on non-msix devices isn't a big deal IMHO.
cheers,
Gerd
Re: [Qemu-devel] [PATCH 12/13] pci: move unregister from PCIDevice to PCIDeviceInfo
Quoted 11 lines · Gerd Hoffmann
Hi,
Quoted 6 lines
Quoted 3 lines
static int
pci_unregister_device(DeviceState *dev)+
msix_uninit(pci_dev);Since devices call
msix_add, I think it is cleaner to have them uninit it as well in their exit routines.Would work too. But this way you can't miss the
msix_uninit()call by accident.
What kind of accident? We don't want a garbage collector in here, do we?
Quoted 6 lines
It also saves a few lines of code.
msix_uninit()carefully
checks whenever msix is actually enabled and it is slow path, so calling it on non-msix devices isn't a big deal IMHO.cheers,
Gerd
Yes, it works, but I find it confusing: IMO init and uninit being in separate modules just makes code impossible to figure out. For example, if there's a failure adding the device, device has to call msix_uninit itself, and IMO it's better to have error handling and cleanup in sync.
Signature · 1 line
MST
Re: [Qemu-devel] [PATCH 12/13] pci: move unregister from PCIDevice to PCIDeviceInfo
Hi,
Quoted 2 lines
Yes, it works, but I find it confusing: IMO init and uninit being in separate modules just makes code impossible to figure out.
Ok, I'll change it for the next respin.
cheers
Gerd
PATCH 13/13 usb: hook unplug into qdev, cleanups + fixes.
In reply to Gerd HoffmannHook into DeviceInfo->exit().
handle_destroy() must not free the state struct, this is handled by the new usb_qdev_exit() function now.
qdev_free(usb_device) works now.
Fix usb hub to qdev_free() all connected devices on unplug. Unplugging a usb hub works now.
--- hw/usb-bt.c | 1 - hw/usb-bus.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++------- hw/usb-hid.c | 1 - hw/usb-hub.c | 6 ++++- hw/usb-msd.c | 2 - hw/usb-serial.c | 1 - hw/usb-wacom.c | 1 - hw/usb.h | 2 + 8 files changed, 56 insertions(+), 15 deletions(-)
hw/usb-bt.c +0 -1
@@ -614,7 +614,6 @@ static void usb_bt_handle_destroy(USBDevice *dev) s->hci->opaque =NULL ; s->hci->evt_recv =NULL ; s->hci->acl_recv =NULL ; -qemu_free (s); }static int usb_bt_initfn (USBDevice *dev)
hw/usb-bus.c +49 -8
87 lines not on this page · raw message
hw/usb-hid.c +0 -1
@@ -843,7 +843,6 @@ static void usb_hid_handle_destroy(USBDevice *dev)if (s->kind !=USB_KEYBOARD )qemu_remove_mouse_event_handler (s->ptr.eh_entry);/* TODO: else */ -qemu_free (s); }static int usb_hid_initfn (USBDevice *dev,int kind)
hw/usb-hub.c +5 -1
@@ -517,8 +517,12 @@ static int usb_hub_handle_packet(USBDevice *dev, USBPacket *p)static void usb_hub_handle_destroy (USBDevice *dev) {USBHubState *s = (USBHubState *)dev; +int i; -qemu_free (s); +for (i =0 ; i < s->nb_ports; i++) { +usb_unregister_port (usb_bus_from_device (dev), + &s->ports[i].port); + } }static int usb_hub_initfn (USBDevice *dev)
hw/usb-msd.c +0 -2
@@ -512,9 +512,7 @@ static void usb_msd_handle_destroy(USBDevice *dev) {MSDState *s = (MSDState *)dev; - s->scsi_dev->info->destroy (s->scsi_dev);drive_uninit (s->dinfo->bdrv); -qemu_free (s); }static int usb_msd_initfn (USBDevice *dev)
hw/usb-serial.c +0 -1
@@ -486,7 +486,6 @@ static void usb_serial_handle_destroy(USBDevice *dev)USBSerialState *s = (USBSerialState *)dev;qemu_chr_close (s->cs); -qemu_free (s); }static int usb_serial_can_read (void *opaque)
hw/usb-wacom.c +0 -1
@@ -389,7 +389,6 @@ static void usb_wacom_handle_destroy(USBDevice *dev)USBWacomState *s = (USBWacomState *) dev;qemu_remove_mouse_event_handler (s->eh_entry); -qemu_free (s); }static int usb_wacom_initfn (USBDevice *dev)
hw/usb.h +2 -0
@@ -311,7 +311,9 @@ USBDevice *usb_create(USBBus *bus, const char *name);USBDevice *usb_create_simple (USBBus *bus,const char *name);void usb_register_port (USBBus *bus,USBPort *port,void *opaque,int index,usb_attachfn attach); +void usb_unregister_port (USBBus *bus,USBPort *port);int usb_device_attach (USBDevice *dev); +int usb_device_detach (USBDevice *dev);int usb_device_delete_addr (int busnr,int addr);static inline USBBus *usb_bus_from_device (USBDevice *d)
Signature · 1 line
1.6.2.5
Your improved commit messages are much appreciated. Run them through a spellchecker, and they're perfect ;)