qdev: replace bus_type enum with bus_info struct.
PATCH 1/1 qdev: replace bus_type enum with bus_info struct.
BusInfo is filled with name and size (pretty much like I did for DeviceInfo as well). There is also a function pointer to print bus-specific device information to the monitor. sysbus is hooked up there, I've also added a print function for PCI.
Device creation is slightly modified as well: The device type search loop now also checks the bus type while scanning the list instead of complaining thereafter in case of a mismatch. This effectively gives each bus a private namespace for device names.
Signed-off-by Gerd Hoffmann <[email protected]>
--- hw/i2c.c | 10 +++++++--- hw/pci.c | 35 ++++++++++++++++++++++++++++++----- hw/qdev.c | 59 ++++++++++++++++++++--------------------------------------- hw/qdev.h | 24 +++++++++++------------- hw/ssi.c | 9 +++++++-- hw/sysbus.c | 12 ++++++++++-- 6 files changed, 85 insertions(+), 64 deletions(-)
hw/i2c.c +7 -3
@@ -17,6 +17,11 @@ struct i2c_busint saved_address; }; +static struct BusInfo i2c_bus_info = { + .name ="I2C" , + .size =sizeof (i2c_bus), +}; +static void i2c_bus_save (QEMUFile *f,void *opaque) {i2c_bus *bus = (i2c_bus *)opaque;
@@ -44,8 +49,7 @@ i2c_bus *i2c_init_bus(DeviceState *parent, const char *name) {i2c_bus *bus; - bus =FROM_QBUS (i2c_bus,qbus_create (BUS_TYPE_I2C ,sizeof (i2c_bus), - parent, name)); + bus =FROM_QBUS (i2c_bus,qbus_create (&i2c_bus_info, parent, name));register_savevm ("i2c_bus" ,-1 ,1 , i2c_bus_save, i2c_bus_load, bus);return bus; }
@@ -156,7 +160,7 @@ void i2c_register_slave(I2CSlaveInfo *info) {assert (info->qdev.size >=sizeof (i2c_slave)); info->qdev.init = i2c_slave_qdev_init; - info->qdev.bus_type =BUS_TYPE_I2C ; + info->qdev.bus_info = &i2c_bus_info;qdev_register (&info->qdev); }
hw/pci.c +30 -5
@@ -46,7 +46,15 @@ struct PCIBus {/* The bus IRQ state is the logical OR of the connected devices. Keep a count of the number of devices with raised IRQs. */ int nirq; -int irq_count[]; +int *irq_count; +}; + +static void pcibus_dev_print (Monitor *mon,DeviceState *dev,int indent); + +static struct BusInfo pci_bus_info = { + .name ="PCI" , + .size =sizeof (PCIBus), + .print = pcibus_dev_print, };static void pci_update_mappings (PCIDevice *d);
@@ -96,14 +104,13 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,PCIBus *bus;static int nbus =0 ; - bus =FROM_QBUS (PCIBus,qbus_create (BUS_TYPE_PCI , -sizeof (PCIBus) + (nirq *sizeof (int )), - parent, name)); + bus =FROM_QBUS (PCIBus,qbus_create (&pci_bus_info, parent, name)); bus->set_irq = set_irq; bus->map_irq = map_irq; bus->irq_opaque = pic; bus->devfn_min = devfn_min; bus->nirq = nirq; + bus->irq_count =qemu_malloc (nirq *sizeof (bus->irq_count[0 ])); bus->next = first_bus; first_bus = bus;register_savevm ("PCIBUS" , nbus++,1 , pcibus_save, pcibus_load, bus);
@@ -927,7 +934,7 @@ void pci_qdev_register(PCIDeviceInfo *info, int count)for (i =0 ; i < count; i++, info++) { info->qdev.init = pci_qdev_init; - info->qdev.bus_type =BUS_TYPE_PCI ; + info->qdev.bus_info = &pci_bus_info;qdev_register (&info->qdev); } }
@@ -942,3 +949,21 @@ PCIDevice *pci_create_simple(PCIBus *bus, int devfn, const char *name)return (PCIDevice *)dev; } + +static void pcibus_dev_print (Monitor *mon,DeviceState *dev,int indent) +{ +PCIDevice *d = (PCIDevice *)dev; +PCIIORegion *r; +int i; + +monitor_printf (mon,"%*saddr %02x:%02x.%x\n" , + indent,"" , d->bus->bus_num, d->devfn >>3 , d->devfn &7 ); +for (i =0 ; i <PCI_NUM_REGIONS ; i++) { + r = &d->io_regions[i]; +if (!r->size) +continue ; +monitor_printf (mon,"%*sbar %d: %s at 0x%x [0x%x]\n" , indent,"" , + i, r->type &PCI_ADDRESS_SPACE_IO ?"i/o" :"mem" , + r->addr, r->addr + r->size -1 ); + } +}
hw/qdev.c +20 -39
105 lines not on this page · raw message
hw/qdev.h +11 -13
@@ -10,6 +10,8 @@ typedef struct DeviceProperty DeviceProperty;typedef struct BusState BusState ; +typedef struct BusInfo BusInfo ; +/* This structure should not be accessed directly. We declare it here so that it can be embedded in individual device state structures. */ struct DeviceState {
@@ -25,19 +27,17 @@ struct DeviceState {LIST_ENTRY (DeviceState) sibling; }; -typedef enum { -BUS_TYPE_SYSTEM , -BUS_TYPE_PCI , -BUS_TYPE_SCSI , -BUS_TYPE_I2C , -BUS_TYPE_SSI , -BUS_TYPE_XEN , -}BusType ; +typedef void (*bus_dev_print )(Monitor *mon,DeviceState *dev,int indent); +struct BusInfo { +const char *name; +size_t size; +bus_dev_print print; +};struct BusState {DeviceState *parent; +BusInfo *info;const char *name; -BusType type; LIST_HEAD(, DeviceState) children;LIST_ENTRY (BusState) sibling; };
@@ -84,7 +84,7 @@ struct DeviceInfo {/* private to qdev / bus */ qdev_initfn init; -BusType bus_type; +BusInfo *bus_info;DevicePropList *props; };
@@ -117,14 +117,12 @@ void *qdev_get_prop_ptr(DeviceState *dev, const char *name);/*** BUS API. ***/ -BusState *qbus_create (BusType type,size_t size, -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)/*** monitor commands ***/ void do_info_qtree (Monitor *mon); -void sysbus_dev_print (Monitor *mon,DeviceState *dev,int indent);#endif
hw/ssi.c +7 -2
@@ -13,6 +13,11 @@ struct SSIBus {BusState qbus; }; +static struct BusInfo ssi_bus_info = { + .name ="SSI" , + .size =sizeof (SSIBus), +}; +static void ssi_slave_init (DeviceState *dev,DeviceInfo *base_info) {SSISlaveInfo *info =container_of (base_info, SSISlaveInfo, qdev);
@@ -33,7 +38,7 @@ void ssi_register_slave(SSISlaveInfo *info) {assert (info->qdev.size >=sizeof (SSISlave)); info->qdev.init = ssi_slave_init; - info->qdev.bus_type =BUS_TYPE_SSI ; + info->qdev.bus_info = &ssi_bus_info;qdev_register (&info->qdev); }
@@ -48,7 +53,7 @@ DeviceState *ssi_create_slave(SSIBus *bus, const char *name)SSIBus *ssi_create_bus (DeviceState *parent,const char *name) {BusState *bus; - bus =qbus_create (BUS_TYPE_SSI ,sizeof (SSIBus), parent, name); + bus =qbus_create (&ssi_bus_info, parent, name);return FROM_QBUS (SSIBus, bus); }
hw/sysbus.c +10 -2
@@ -22,6 +22,14 @@#include "sysemu.h" #include "monitor.h" +static void sysbus_dev_print (Monitor *mon,DeviceState *dev,int indent); + +struct BusInfo system_bus_info = { + .name ="System" , + .size =sizeof (BusState), + .print = sysbus_dev_print, +}; +void sysbus_connect_irq (SysBusDevice *dev,int n,qemu_irq irq) {assert (n >=0 && n < dev->num_irq);
@@ -108,7 +116,7 @@ static void sysbus_device_init(DeviceState *dev, DeviceInfo *base)void sysbus_register_withprop (SysBusDeviceInfo *info) { info->qdev.init = sysbus_device_init; - info->qdev.bus_type =BUS_TYPE_SYSTEM ; + info->qdev.bus_info = &system_bus_info;assert (info->qdev.size >=sizeof (SysBusDevice));qdev_register (&info->qdev);
@@ -153,7 +161,7 @@ DeviceState *sysbus_create_varargs(const char *name,return dev; } -void sysbus_dev_print (Monitor *mon,DeviceState *dev,int indent) +static void sysbus_dev_print (Monitor *mon,DeviceState *dev,int indent) {SysBusDevice *s =sysbus_from_qdev (dev);int i;
Signature · 1 line
1.6.2.2