qdev patches.
cover qdev patches.
Hi,
This is a respin of my qdev patches. They are rebased to the latest master.
The first two patches are almost unmodified since the last time I posted them, I think they are ready to be merged. The pci registration patch addresses the pci config space access issue, which must be fixed because otherwise some PCI drivers can't be converted to qdev.
The other patches switch over various drivers and busses to qdev. They depend on the first two patches. The conversion work is far from being completed. Currently my main focus is on getting all devices into the qdev tree. Most drivers are not (yet) in a state where creating them from a fdt can actually work though. IMHO the patches are useful nevertheless. YMMV, feel free to cherry-pick some of the patches only.
Open issues:
usb: The way qemu manages usb ports, hubs and busses needs fixing.
Right now qemu manages ports only.
scsi: linking host-devs + guest-devs isn't solved yet.
Needed for bdrv + scsi-disk to complete scsi conversion.
ide: not even started yet.
The patches can also be pulled from
git://git.et.redhat.com/qemu-kraxel.git (branch qdev.v4).
Note: the git tree also has the alsa warning fix so the tree actually builds ...
cheers,
Gerd
PATCH 1/10 qdev: update pci device registration.
Makes pci_qdev_register take a PCIDeviceInfo struct instead of a bunch of parameters. Also adds config_read and config_write callbacks to PCIDeviceInfo, so drivers needing these can be converted to the qdev device API too.
--- hw/e1000.c | 8 +++++++- hw/eepro100.c | 23 +++++++++++++++++------ hw/lsi53c895a.c | 8 +++++++- hw/ne2000.c | 8 +++++++- hw/pci.c | 24 ++++++++---------------- hw/pci.h | 9 ++++++++- hw/pcnet.c | 8 +++++++- hw/rtl8139.c | 8 +++++++- hw/versatile_pci.c | 9 +++++++-- hw/virtio-pci.c | 29 +++++++++++++++++++++-------- 10 files changed, 96 insertions(+), 38 deletions(-)
hw/e1000.c +7 -1
@@ -1133,9 +1133,15 @@ static void pci_e1000_init(PCIDevice *pci_dev)e1000_reset (d); } +static PCIDeviceInfo e1000_info = { + .qdev.name ="e1000" , + .qdev.size =sizeof (E1000State), + .init = pci_e1000_init, +}; +static void e1000_register_devices (void ) { -pci_qdev_register ("e1000" ,sizeof (E1000State), pci_e1000_init); +pci_qdev_register (&e1000_info,1 ); }device_init (e1000_register_devices)
hw/eepro100.c +17 -6
@@ -1792,14 +1792,25 @@ static void pci_i82559er_init(PCIDevice *dev)nic_init (dev, i82559ER); } +static PCIDeviceInfo eepro100_info[] = { + { + .qdev.name ="i82551" , + .qdev.size =sizeof (PCIEEPRO100State), + .init = pci_i82551_init, + },{ + .qdev.name ="i82557b" , + .qdev.size =sizeof (PCIEEPRO100State), + .init = pci_i82557b_init, + },{ + .qdev.name ="i82559er" , + .qdev.size =sizeof (PCIEEPRO100State), + .init = pci_i82559er_init, + } +}; +static void eepro100_register_devices (void ) { -pci_qdev_register ("i82551" ,sizeof (PCIEEPRO100State), - pci_i82551_init); -pci_qdev_register ("i82557b" ,sizeof (PCIEEPRO100State), - pci_i82557b_init); -pci_qdev_register ("i82559er" ,sizeof (PCIEEPRO100State), - pci_i82559er_init); +pci_qdev_register (eepro100_info,ARRAY_SIZE (eepro100_info)); }device_init (eepro100_register_devices)
hw/lsi53c895a.c +7 -1
@@ -2035,9 +2035,15 @@ static void lsi_scsi_init(PCIDevice *dev)scsi_bus_new (&dev->qdev, lsi_scsi_attach); } +static PCIDeviceInfo lsi_info = { + .qdev.name ="lsi53c895a" , + .qdev.size =sizeof (LSIState), + .init = lsi_scsi_init, +}; +static void lsi53c895a_register_devices (void ) { -pci_qdev_register ("lsi53c895a" ,sizeof (LSIState), lsi_scsi_init); +pci_qdev_register (&lsi_info,1 ); }device_init (lsi53c895a_register_devices);
hw/ne2000.c +7 -1
@@ -832,9 +832,15 @@ static void pci_ne2000_init(PCIDevice *pci_dev)register_savevm ("ne2000" ,-1 ,3 , ne2000_save, ne2000_load, s); } +static PCIDeviceInfo ne2000_info = { + .qdev.name ="ne2k_pci" , + .qdev.size =sizeof (PCINE2000State), + .init = pci_ne2000_init, +}; +static void ne2000_register_devices (void ) { -pci_qdev_register ("ne2k_pci" ,sizeof (PCINE2000State), pci_ne2000_init); +pci_qdev_register (&ne2000_info,1 ); }device_init (ne2000_register_devices)
hw/pci.c +8 -16
@@ -899,11 +899,6 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did,return s->bus; } -typedef struct { -DeviceInfo qdev; -pci_qdev_initfn init; -}PCIDeviceInfo ; -static void pci_qdev_init (DeviceState *qdev,DeviceInfo *base) {PCIDevice *pci_dev = (PCIDevice *)qdev;
@@ -914,23 +909,20 @@ static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base) bus =FROM_QBUS (PCIBus,qdev_get_parent_bus (qdev)); devfn =qdev_get_prop_int (qdev,"devfn" ,-1 ); pci_dev =do_pci_register_device (pci_dev, bus,"FIXME" , devfn, -NULL ,NULL );//FIXME:config_read, config_write); + info->config_read, info->config_write);assert (pci_dev); info->init (pci_dev); } -void pci_qdev_register (const char *name,int size,pci_qdev_initfn init) +void pci_qdev_register (PCIDeviceInfo *info,int count) { -PCIDeviceInfo *info; - - info =qemu_mallocz (sizeof (*info)); - info->qdev.name =qemu_strdup (name); - info->qdev.size = size; - info->init = init; - info->qdev.init = pci_qdev_init; - info->qdev.bus_type =BUS_TYPE_PCI ; +int i; -qdev_register (&info->qdev); +for (i =0 ; i < count; i++, info++) { + info->qdev.init = pci_qdev_init; + info->qdev.bus_type =BUS_TYPE_PCI ; +qdev_register (&info->qdev); + } }PCIDevice *pci_create_simple (PCIBus *bus,int devfn,const char *name)
hw/pci.h +8 -1
@@ -218,7 +218,14 @@ pci_config_set_class(uint8_t *pci_config, uint16_t val) }typedef void (*pci_qdev_initfn )(PCIDevice *dev); -void pci_qdev_register (const char *name,int size,pci_qdev_initfn init); +typedef struct { +DeviceInfo qdev; +pci_qdev_initfn init; +PCIConfigReadFunc *config_read; +PCIConfigWriteFunc *config_write; +}PCIDeviceInfo ; + +void pci_qdev_register (PCIDeviceInfo *info,int count);PCIDevice *pci_create_simple (PCIBus *bus,int devfn,const char *name);
hw/pcnet.c +7 -1
@@ -2143,9 +2143,15 @@ static void lance_init(SysBusDevice *dev) }#endif /* TARGET_SPARC */ +static PCIDeviceInfo pcnet_info = { + .qdev.name ="pcnet" , + .qdev.size =sizeof (PCIPCNetState), + .init = pci_pcnet_init, +}; +static void pcnet_register_devices (void ) { -pci_qdev_register ("pcnet" ,sizeof (PCIPCNetState), pci_pcnet_init); +pci_qdev_register (&pcnet_info,1 );#if defined (TARGET_SPARC ) && !defined(TARGET_SPARC64 )sysbus_register_dev ("lance" ,sizeof (SysBusPCNetState), lance_init);#endif
hw/rtl8139.c +7 -1
@@ -3501,9 +3501,15 @@ static void pci_rtl8139_init(PCIDevice *dev)#endif /* RTL8139_ONBOARD_TIMER */ } +static PCIDeviceInfo rtl8139_info = { + .qdev.name ="rtl8139" , + .qdev.size =sizeof (PCIRTL8139State), + .init = pci_rtl8139_init, +}; +static void rtl8139_register_devices (void ) { -pci_qdev_register ("rtl8139" ,sizeof (PCIRTL8139State), pci_rtl8139_init); +pci_qdev_register (&rtl8139_info,1 ); }device_init (rtl8139_register_devices)
hw/versatile_pci.c +7 -2
@@ -153,13 +153,18 @@ static void versatile_pci_host_init(PCIDevice *d) d->config[0x0D ] =0x10 ;// latency_timer } +static PCIDeviceInfo versatile_pci_host_info = { + .qdev.name ="versatile_pci_host" , + .qdev.size =sizeof (PCIDevice), + .init = versatile_pci_host_init, +}; +static void versatile_pci_register_devices (void ) {sysbus_register_dev ("versatile_pci" ,sizeof (PCIVPBState), pci_vpb_init);sysbus_register_dev ("realview_pci" ,sizeof (PCIVPBState), pci_realview_init); -pci_qdev_register ("versatile_pci_host" ,sizeof (PCIDevice), - versatile_pci_host_init); +pci_qdev_register (&versatile_pci_host_info,1 ); }device_init (versatile_pci_register_devices)
hw/virtio-pci.c +21 -8
@@ -334,16 +334,29 @@ static void virtio_balloon_init_pci(PCIDevice *pci_dev) 0x00); } +static PCIDeviceInfo virtio_info[] = { + { + .qdev.name ="virtio-blk-pci" , + .qdev.size =sizeof (VirtIOPCIProxy), + .init = virtio_blk_init_pci, + },{ + .qdev.name ="virtio-net-pci" , + .qdev.size =sizeof (VirtIOPCIProxy), + .init = virtio_net_init_pci, + },{ + .qdev.name ="virtio-console-pci" , + .qdev.size =sizeof (VirtIOPCIProxy), + .init = virtio_console_init_pci, + },{ + .qdev.name ="virtio-balloon-pci" , + .qdev.size =sizeof (VirtIOPCIProxy), + .init = virtio_balloon_init_pci, + } +}; +static void virtio_pci_register_devices (void ) { -pci_qdev_register ("virtio-blk-pci" ,sizeof (VirtIOPCIProxy), - virtio_blk_init_pci); -pci_qdev_register ("virtio-net-pci" ,sizeof (VirtIOPCIProxy), - virtio_net_init_pci); -pci_qdev_register ("virtio-console-pci" ,sizeof (VirtIOPCIProxy), - virtio_console_init_pci); -pci_qdev_register ("virtio-balloon-pci" ,sizeof (VirtIOPCIProxy), - virtio_balloon_init_pci); +pci_qdev_register (virtio_info,ARRAY_SIZE (virtio_info)); }device_init (virtio_pci_register_devices)
Signature · 1 line
1.6.2.2
PATCH 2/10 qdev: replace bus_type enum with bus_info struct.
In reply to Gerd HoffmannBusInfo 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.
--- hw/i2c.c | 10 +++++++--- hw/pci.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++----- hw/qdev.c | 58 ++++++++++++++++++++-------------------------------------- hw/qdev.h | 23 +++++++++++------------ hw/ssi.c | 9 +++++++-- hw/sysbus.c | 12 ++++++++++-- 6 files changed, 103 insertions(+), 62 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 +48 -5
79 lines not on this page · raw message
hw/qdev.c +20 -38
104 lines not on this page · raw message
hw/qdev.h +11 -12
@@ -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,18 +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 -}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 +85,7 @@ struct DeviceInfo {/* Private to qdev / bus. */ qdev_initfn init; -BusType bus_type; +BusInfo *bus_info; };void qdev_register (DeviceInfo *info);
@@ -116,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
PATCH 3/10 qdev: remove DeviceType
In reply to Gerd HoffmannThe only purpose DeviceType serves is creating a linked list of DeviceInfo structs. This removes DeviceType and add a next field to DeviceInfo instead, so the DeviceInfo structs can be changed that way. Elimitates a pointless extra level of indirection.
--- hw/qdev.c | 37 ++++++++++++++----------------------- hw/qdev.h | 7 +++---- 2 files changed, 17 insertions(+), 27 deletions(-)
hw/qdev.c +14 -23
@@ -41,28 +41,19 @@ struct DeviceProperty {DeviceProperty *next; }; -struct DeviceType { -DeviceInfo *info; -DeviceType *next; -}; -/* This is a nasty hack to allow passing a NULL bus to qdev_create. */ static BusState *main_system_bus;extern struct BusInfo system_bus_info; -static DeviceType *device_type_list; +static DeviceInfo *device_info_list;/* Register a new device type. */ void qdev_register (DeviceInfo *info) { -DeviceType *t; -assert (info->size >=sizeof (DeviceState)); - t =qemu_mallocz (sizeof (DeviceType)); - t->next = device_type_list; - device_type_list = t; - t->info = info; + info->next = device_info_list; + device_info_list = info; }/* Create a new device. This only initializes the device state structure
@@ -70,7 +61,7 @@ void qdev_register(DeviceInfo *info)initialize the actual device emulation. */ DeviceState *qdev_create (BusState *bus,const char *name) { -DeviceType *t; +DeviceInfo *info;DeviceState *dev;if (!bus) {
@@ -80,19 +71,19 @@ DeviceState *qdev_create(BusState *bus, const char *name) bus = main_system_bus; } -for (t = device_type_list; t; t = t->next) { -if (t->info->bus_info != bus->info) +for (info = device_info_list; info !=NULL ; info = info->next) { +if (info->bus_info != bus->info)continue ; -if (strcmp (t->info->name, name) !=0 ) +if (strcmp (info->name, name) !=0 )continue ;break ; } -if (!t) { +if (!info) {hw_error ("Unknown device '%s' for bus '%s'\n" , name, bus->info->name); } - dev =qemu_mallocz (t->info->size); - dev->type = t; + dev =qemu_mallocz (info->size); + dev->info = info; dev->parent_bus = bus;LIST_INSERT_HEAD (&bus->children, dev, sibling);return dev;
@@ -103,7 +94,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)calling this function. */ void qdev_init (DeviceState *dev) { - dev->type->info->init (dev, dev->type->info); + dev->info->init (dev, dev->info); }/* Unlink device from bus and free the structure. */
@@ -165,7 +156,7 @@ CharDriverState *qdev_init_chardev(DeviceState *dev)static int next_serial;static int next_virtconsole;/* FIXME: This is a nasty hack that needs to go away. */ -if (strncmp (dev->type->info->name,"virtio" ,6 ) ==0 ) { +if (strncmp (dev->info->name,"virtio" ,6 ) ==0 ) {return virtcon_hds[next_virtconsole++]; }else {return serial_hds[next_serial++];
@@ -338,7 +329,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent) {DeviceProperty *prop;BusState *child; -qdev_printf ("dev: %s\n" , dev->type->info->name); +qdev_printf ("dev: %s\n" , dev->info->name); indent +=2 ;if (dev->num_gpio_in) {qdev_printf ("gpio-in %d\n" , dev->num_gpio_in);
@@ -357,7 +348,7 @@ static void qdev_print(Monitor *mon, DeviceState *dev, int indent)break ;case PROP_TYPE_DEV :qdev_printf ("prop-dev %s %s\n" , prop->name, - ((DeviceState *)prop->value.ptr)->type->info->name); + ((DeviceState *)prop->value.ptr)->info->name);break ;default :qdev_printf ("prop-unknown%d %s\n" , prop->type, prop->name);
hw/qdev.h +3 -4
@@ -4,7 +4,7 @@#include "hw.h" #include "sys-queue.h" -typedef struct DeviceType DeviceType ; +typedef struct DeviceInfo DeviceInfo ;typedef struct DeviceProperty DeviceProperty ;
@@ -15,7 +15,7 @@ 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 { -DeviceType *type; +DeviceInfo *info;BusState *parent_bus;DeviceProperty *props;int num_gpio_out;
@@ -72,8 +72,6 @@ typedef struct {DevicePropType type; } DevicePropList; -typedef struct DeviceInfo DeviceInfo ; -typedef void (*qdev_initfn )(DeviceState *dev,DeviceInfo *info);typedef void (*SCSIAttachFn )(DeviceState *host,BlockDriverState *bdrv,int unit);
@@ -86,6 +84,7 @@ struct DeviceInfo {/* Private to qdev / bus. */ qdev_initfn init;BusInfo *bus_info; +struct DeviceInfo *next; };void qdev_register (DeviceInfo *info);
Signature · 1 line
1.6.2.2
PATCH 4/10 qdev/pci: bus name
In reply to Gerd Hoffmann--- hw/pci.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/pci.c +6 -0
@@ -101,6 +101,12 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name, {PCIBus *bus;static int nbus =0 ; +char defname[32 ]; + +if (!name) { +snprintf (defname,sizeof (defname),"pci%d" , nbus); + name = defname; + } bus =FROM_QBUS (PCIBus,qbus_create (&pci_bus_info, parent, name)); bus->set_irq = set_irq;
Signature · 1 line
1.6.2.2
PATCH 5/10 qdev: hook up i440fx.
In reply to Gerd HoffmannHook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev.
--- hw/pci_host.h | 3 ++ hw/piix_pci.c | 93 +++++++++++++++++++++++++++++++++++++++++---------------- 2 files changed, 70 insertions(+), 26 deletions(-)
hw/pci_host.h +3 -0
@@ -28,6 +28,8 @@/* debug PCI */ //#define DEBUG_PCI +#include "sysbus.h" +#ifdef DEBUG_PCI #define PCI_DPRINTF (fmt, ...) \ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)
@@ -36,6 +38,7 @@ do { printf("pci_host_data: " fmt , ## __VA_ARGS__); } while (0)#endif typedef struct { +SysBusDevice busdev;uint32_t config_reg;PCIBus *bus; }PCIHostState ;
hw/piix_pci.c +67 -26
153 lines not on this page · raw message
Signature · 1 line
1.6.2.2
PATCH 6/10 qdev: convert piix-ide, first step
In reply to Gerd Hoffmann--- hw/ide.c | 90 ++++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 59 insertions(+), 31 deletions(-)
hw/ide.c +59 -31
@@ -3360,20 +3360,11 @@ static void piix3_reset(void *opaque) pci_conf[0x20 ] =0x01 ;/* BMIBA: 20-23h */ } -/* hd_table must contain 4 block drivers */ -/* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */ -void pci_piix3_ide_init (PCIBus *bus,BlockDriverState **hd_table,int devfn, -qemu_irq *pic) +static void pci_piix3_ide_initfn (PCIDevice *dev) { -PCIIDEState *d; +PCIIDEState *d =DO_UPCAST (PCIIDEState, dev, dev);uint8_t *pci_conf; -int i; -/* register a function 1 of PIIX3 */ - d = (PCIIDEState *)pci_register_device (bus,"PIIX3 IDE" , -sizeof (PCIIDEState), - devfn, -NULL ,NULL ); d->type =IDE_TYPE_PIIX3 ; pci_conf = d->dev.config;
@@ -3389,31 +3380,14 @@ void pci_piix3_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,pci_register_bar ((PCIDevice *)d,4 ,0x10 ,PCI_ADDRESS_SPACE_IO , bmdma_map); -ide_init2 (&d->ide_if[0 ], hd_table[0 ], hd_table[1 ], pic[14 ]); -ide_init2 (&d->ide_if[2 ], hd_table[2 ], hd_table[3 ], pic[15 ]); -ide_init_ioport (&d->ide_if[0 ],0x1f0 ,0x3f6 ); -ide_init_ioport (&d->ide_if[2 ],0x170 ,0x376 ); - -for (i =0 ; i <4 ; i++) -if (hd_table[i]) - hd_table[i]->private = &d->dev; -register_savevm ("ide" ,0 ,2 , pci_ide_save, pci_ide_load, d); } -/* hd_table must contain 4 block drivers */ -/* NOTE: for the PIIX4, the IRQs and IOports are hardcoded */ -void pci_piix4_ide_init (PCIBus *bus,BlockDriverState **hd_table,int devfn, -qemu_irq *pic) +static void pci_piix4_ide_initfn (PCIDevice *dev) { -PCIIDEState *d; +PCIIDEState *d =DO_UPCAST (PCIIDEState, dev, dev);uint8_t *pci_conf; -/* register a function 1 of PIIX4 */ - d = (PCIIDEState *)pci_register_device (bus,"PIIX4 IDE" , -sizeof (PCIIDEState), - devfn, -NULL ,NULL ); d->type =IDE_TYPE_PIIX4 ; pci_conf = d->dev.config;
@@ -3429,13 +3403,67 @@ void pci_piix4_ide_init(PCIBus *bus, BlockDriverState **hd_table, int devfn,pci_register_bar ((PCIDevice *)d,4 ,0x10 ,PCI_ADDRESS_SPACE_IO , bmdma_map); +register_savevm ("ide" ,0 ,2 , pci_ide_save, pci_ide_load, d); +} + +/* hd_table must contain 4 block drivers */ +/* NOTE: for the PIIX3, the IRQs and IOports are hardcoded */ +void pci_piix3_ide_init (PCIBus *bus,BlockDriverState **hd_table,int devfn, +qemu_irq *pic) +{ +PCIDevice *dev; +PCIIDEState *d; +int i; + + dev =pci_create_simple (bus, devfn,"PIIX3 IDE" ); + d =DO_UPCAST (PCIIDEState, dev, dev); + +/* TODO: ide bus */ ide_init2 (&d->ide_if[0 ], hd_table[0 ], hd_table[1 ], pic[14 ]);ide_init2 (&d->ide_if[2 ], hd_table[2 ], hd_table[3 ], pic[15 ]);ide_init_ioport (&d->ide_if[0 ],0x1f0 ,0x3f6 );ide_init_ioport (&d->ide_if[2 ],0x170 ,0x376 ); -register_savevm ("ide" ,0 ,2 , pci_ide_save, pci_ide_load, d); +for (i =0 ; i <4 ; i++) +if (hd_table[i]) + hd_table[i]->private = &d->dev; +} + +/* hd_table must contain 4 block drivers */ +/* NOTE: for the PIIX4, the IRQs and IOports are hardcoded */ +void pci_piix4_ide_init (PCIBus *bus,BlockDriverState **hd_table,int devfn, +qemu_irq *pic) +{ +PCIDevice *dev; +PCIIDEState *d; + + dev =pci_create_simple (bus, devfn,"PIIX4 IDE" ); + d =DO_UPCAST (PCIIDEState, dev, dev); + +/* TODO: ide bus */ +ide_init2 (&d->ide_if[0 ], hd_table[0 ], hd_table[1 ], pic[14 ]); +ide_init2 (&d->ide_if[2 ], hd_table[2 ], hd_table[3 ], pic[15 ]); +ide_init_ioport (&d->ide_if[0 ],0x1f0 ,0x3f6 ); +ide_init_ioport (&d->ide_if[2 ],0x170 ,0x376 ); +} + +static PCIDeviceInfo piix_ide_info[] = { + { + .qdev.name ="PIIX3 IDE" , + .qdev.size =sizeof (PCIIDEState), + .init = pci_piix3_ide_initfn, + },{ + .qdev.name ="PIIX4 IDE" , + .qdev.size =sizeof (PCIIDEState), + .init = pci_piix4_ide_initfn, + } +}; + +static void piix_ide_register (void ) +{ +pci_qdev_register (piix_ide_info,ARRAY_SIZE (piix_ide_info)); } +device_init (piix_ide_register);#if defined(TARGET_PPC )/***********************************************************/
Signature · 1 line
1.6.2.2
PATCH 7/10 qdev-ify: piix acpi
In reply to Gerd Hoffmann--- hw/acpi.c | 46 ++++++++++++++++++++++++++++++++++------------ 1 files changed, 34 insertions(+), 12 deletions(-)
hw/acpi.c +34 -12
@@ -497,15 +497,11 @@ static void piix4_reset(void *opaque) } } -i2c_bus *piix4_pm_init (PCIBus *bus,int devfn,uint32_t smb_io_base, -qemu_irq sci_irq) +static void piix4_pm_initfn (PCIDevice *dev) { -PIIX4PMState *s; -uint8_t *pci_conf; +PIIX4PMState *s =DO_UPCAST (PIIX4PMState, dev, dev); +uint8_t *pci_conf = s->dev.config; - s = (PIIX4PMState *)pci_register_device (bus, -"PM" ,sizeof (PIIX4PMState), - devfn,NULL , pm_write_config); pm_state = s; pci_conf = s->dev.config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL );
@@ -538,23 +534,49 @@ i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, pci_conf[0x67 ] = (serial_hds[0 ] !=NULL ?0x08 :0 ) | (serial_hds[1 ] !=NULL ?0x90 :0 ); + s->tmr_timer =qemu_new_timer (vm_clock, pm_tmr_timer, s); + +register_savevm ("piix4_pm" ,0 ,1 , pm_save, pm_load, s); + +} + +i2c_bus *piix4_pm_init (PCIBus *bus,int devfn,uint32_t smb_io_base, +qemu_irq sci_irq) +{ +PCIDevice *dev; +PIIX4PMState *s; +uint8_t *pci_conf; + + dev =pci_create_simple (bus, devfn,"PM" ); + s =DO_UPCAST (PIIX4PMState, dev, dev); + + pci_conf = s->dev.config; pci_conf[0x90 ] = smb_io_base |1 ; pci_conf[0x91 ] = smb_io_base >>8 ; pci_conf[0xd2 ] =0x09 ;register_ioport_write (smb_io_base,64 ,1 , smb_ioport_writeb, s);register_ioport_read (smb_io_base,64 ,1 , smb_ioport_readb, s); + s->smbus =i2c_init_bus (&s->dev.qdev,"i2c" ); - s->tmr_timer =qemu_new_timer (vm_clock, pm_tmr_timer, s); - -register_savevm ("piix4_pm" ,0 ,1 , pm_save, pm_load, s); - - s->smbus =i2c_init_bus (NULL ,"i2c" ); s->irq = sci_irq;qemu_register_reset (piix4_reset,0 , s);return s->smbus; } +static PCIDeviceInfo acpi_info = { + .qdev.name ="PM" , + .qdev.size =sizeof (PIIX4PMState), + .init = piix4_pm_initfn, + .config_write = pm_write_config, +}; + +static void acpi_register (void ) +{ +pci_qdev_register (&acpi_info,1 ); +} +device_init (acpi_register); +#if defined(TARGET_I386 )void qemu_system_powerdown (void ) {
Signature · 1 line
1.6.2.2
PATCH 8/10 qdev-ify: uhci
In reply to Gerd Hoffmann--- hw/usb-uhci.c | 71 +++++++++++++++++++++++++++++++------------------------- 1 files changed, 39 insertions(+), 32 deletions(-)
hw/usb-uhci.c +39 -32
@@ -1069,18 +1069,11 @@ static void uhci_map(PCIDevice *pci_dev, int region_num,register_ioport_read (addr,32 ,1 , uhci_ioport_readb, s); } -void usb_uhci_piix3_init (PCIBus *bus,int devfn) +static void usb_uhci_common_initfn (UHCIState *s) { -UHCIState *s; -uint8_t *pci_conf; +uint8_t *pci_conf = s->dev.config;int i; - s = (UHCIState *)pci_register_device (bus, -"USB-UHCI" ,sizeof (UHCIState), - devfn,NULL ,NULL ); - pci_conf = s->dev.config; -pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL ); -pci_config_set_device_id (pci_conf,PCI_DEVICE_ID_INTEL_82371SB_2 ); pci_conf[0x08 ] =0x01 ;// revision number pci_conf[0x09 ] =0x00 ;pci_config_set_class (pci_conf,PCI_CLASS_SERIAL_USB );
@@ -1103,36 +1096,50 @@ void usb_uhci_piix3_init(PCIBus *bus, int devfn)register_savevm ("uhci" ,0 ,1 , uhci_save, uhci_load, s); } -void usb_uhci_piix4_init (PCIBus *bus,int devfn) +static void usb_uhci_piix3_initfn (PCIDevice *dev) { -UHCIState *s; -uint8_t *pci_conf; -int i; +UHCIState *s =DO_UPCAST (UHCIState, dev, dev); +uint8_t *pci_conf = s->dev.config; + +pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL ); +pci_config_set_device_id (pci_conf,PCI_DEVICE_ID_INTEL_82371SB_2 ); +usb_uhci_common_initfn (s); +} + +static void usb_uhci_piix4_initfn (PCIDevice *dev) +{ +UHCIState *s =DO_UPCAST (UHCIState, dev, dev); +uint8_t *pci_conf = s->dev.config; - s = (UHCIState *)pci_register_device (bus, -"USB-UHCI" ,sizeof (UHCIState), - devfn,NULL ,NULL ); - pci_conf = s->dev.config;pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_INTEL );pci_config_set_device_id (pci_conf,PCI_DEVICE_ID_INTEL_82371AB_2 ); - pci_conf[0x08 ] =0x01 ;// revision number - pci_conf[0x09 ] =0x00 ; -pci_config_set_class (pci_conf,PCI_CLASS_SERIAL_USB ); - pci_conf[PCI_HEADER_TYPE ] =PCI_HEADER_TYPE_NORMAL ;// header_type - pci_conf[0x3d ] =4 ;// interrupt pin 3 - pci_conf[0x60 ] =0x10 ;// release number +usb_uhci_common_initfn (s); +} -for (i =0 ; i <NB_PORTS ; i++) { -qemu_register_usb_port (&s->ports[i].port, s, i, uhci_attach); +static PCIDeviceInfo uhci_info[] = { + { + .qdev.name ="PIIX3 USB-UHCI" , + .qdev.size =sizeof (UHCIState), + .init = usb_uhci_piix3_initfn, + },{ + .qdev.name ="PIIX4 USB-UHCI" , + .qdev.size =sizeof (UHCIState), + .init = usb_uhci_piix4_initfn, } - s->frame_timer =qemu_new_timer (vm_clock, uhci_frame_timer, s); +}; -uhci_reset (s); +static void acpi_register (void ) +{ +pci_qdev_register (uhci_info,ARRAY_SIZE (uhci_info)); +} +device_init (acpi_register); -/* Use region 4 for consistency with real hardware. BSD guests seem -to rely on this. */ -pci_register_bar (&s->dev,4 ,0x20 , -PCI_ADDRESS_SPACE_IO , uhci_map); +void usb_uhci_piix3_init (PCIBus *bus,int devfn) +{ +pci_create_simple (bus, devfn,"PIIX3 USB-UHCI" ); +} -register_savevm ("uhci" ,0 ,1 , uhci_save, uhci_load, s); +void usb_uhci_piix4_init (PCIBus *bus,int devfn) +{ +pci_create_simple (bus, devfn,"PIIX4 USB-UHCI" ); }
Signature · 1 line
1.6.2.2
PATCH 9/10 qdev-ify: usb
In reply to Gerd Hoffmann--- Makefile | 2 +- hw/bt-hid.c | 18 +++++----- hw/usb-bt.c | 37 ++++++++++++++----- hw/usb-bus.c | 61 ++++++++++++++++++++++++++++++++ hw/usb-hid.c | 103 +++++++++++++++++++++++++++++++----------------------- hw/usb-hub.c | 48 +++++++++++++++----------- hw/usb-msd.c | 44 +++++++++++++++-------- hw/usb-musb.c | 2 +- hw/usb-net.c | 44 ++++++++++++++++------- hw/usb-ohci.c | 4 +- hw/usb-serial.c | 47 ++++++++++++++++-------- hw/usb-uhci.c | 4 ++- hw/usb-wacom.c | 33 +++++++++++------ hw/usb.c | 16 ++++---- hw/usb.h | 61 ++++++++++++++++++++------------ usb-linux.c | 52 +++++++++++++++++++-------- vl.c | 4 +- 17 files changed, 387 insertions(+), 193 deletions(-) create mode 100644 hw/usb-bus.c
Makefile +1 -1
@@ -102,7 +102,7 @@ OBJS+=tmp105.o lm832x.o eeprom93xx.o tsc2005.o OBJS+=scsi-disk.o cdrom.o OBJS+=scsi-generic.o OBJS+=usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o -OBJS+=usb-serial.o usb-net.o +OBJS+=usb-serial.o usb-net.o usb-bus.o OBJS+=sd.o ssi-sd.o OBJS+=bt.o bt-host.o bt-vhci.o bt-l2cap.o bt-sdp.o bt-hci.o bt-hid.o usb-bt.o OBJS+=bt-hci-csr.o
hw/bt-hid.c +9 -9
@@ -112,7 +112,7 @@ static void bt_hid_reset(struct bt_hid_device_s *s)bt_l2cap_device_done (&s->btdev);bt_l2cap_device_init (&s->btdev, net); - s->usbdev->handle_reset (s->usbdev); + s->usbdev->info->handle_reset (s->usbdev); s->proto =BT_HID_PROTO_REPORT ; s->state = bt_state_ready; s->dataother.len =0 ;
@@ -132,7 +132,7 @@ static int bt_hid_out(struct bt_hid_device_s *s) p.devep =1 ; p.data = s->dataout.buffer; p.len = s->dataout.len; - s->dataout.len = s->usbdev->handle_data (s->usbdev, &p); + s->dataout.len = s->usbdev->info->handle_data (s->usbdev, &p);return s->dataout.len; }
@@ -155,7 +155,7 @@ static int bt_hid_in(struct bt_hid_device_s *s) p.devep =1 ; p.data = s->datain.buffer; p.len =sizeof (s->datain.buffer); - s->datain.len = s->usbdev->handle_data (s->usbdev, &p); + s->datain.len = s->usbdev->info->handle_data (s->usbdev, &p);return s->datain.len; }
@@ -324,8 +324,8 @@ static void bt_hid_control_transaction(struct bt_hid_device_s *s,break ; } s->proto = parameter; - s->usbdev->handle_control (s->usbdev,SET_PROTOCOL , s->proto,0 ,0 , -NULL ); + s->usbdev->info->handle_control (s->usbdev,SET_PROTOCOL , s->proto,0 ,0 , +NULL ); ret =BT_HS_SUCCESSFUL ;break ;
@@ -334,7 +334,7 @@ static void bt_hid_control_transaction(struct bt_hid_device_s *s, ret =BT_HS_ERR_INVALID_PARAMETER ;break ; } - s->usbdev->handle_control (s->usbdev,GET_IDLE ,0 ,0 ,1 , + s->usbdev->info->handle_control (s->usbdev,GET_IDLE ,0 ,0 ,1 , s->control->sdu_out (s->control,1 )); s->control->sdu_submit (s->control);break ;
@@ -347,7 +347,7 @@ static void bt_hid_control_transaction(struct bt_hid_device_s *s,/* We don't need to know about the Idle Rate here really, * so just pass it on to the device. */ - ret = s->usbdev->handle_control (s->usbdev, + ret = s->usbdev->info->handle_control (s->usbdev,SET_IDLE , data[1 ],0 ,0 ,NULL ) ?BT_HS_SUCCESSFUL :BT_HS_ERR_INVALID_PARAMETER ;/* XXX: Does this generate a handshake? */
@@ -451,7 +451,7 @@ static void bt_hid_connected_update(struct bt_hid_device_s *hid) hid->btdev.device.inquiry_scan = !hid->connected;if (hid->connected && !prev) { - hid->usbdev->handle_reset (hid->usbdev); + hid->usbdev->info->handle_reset (hid->usbdev); hid->proto =BT_HID_PROTO_REPORT ; }
@@ -519,7 +519,7 @@ static void bt_hid_destroy(struct bt_device_s *dev)bt_hid_send_control (hid,BT_HC_VIRTUAL_CABLE_UNPLUG );bt_l2cap_device_done (&hid->btdev); - hid->usbdev->handle_destroy (hid->usbdev); + hid->usbdev->info->handle_destroy (hid->usbdev);qemu_free (hid); }
hw/usb-bt.c +27 -10
@@ -618,22 +618,22 @@ static void usb_bt_handle_destroy(USBDevice *dev)qemu_free (s); } +static void usb_bt_initfn (USBDevice *dev) +{ + struct USBBtState *s = DO_UPCAST(struct USBBtState, dev, dev); + s->dev.speed =USB_SPEED_HIGH ; +} +USBDevice *usb_bt_init (HCIInfo *hci) { +USBDevice *dev;struct USBBtState *s;if (!hci)return NULL ; - s =qemu_mallocz (sizeof (struct USBBtState )); + dev =usb_create_simple (NULL /* FIXME */ ,"QEMU BT dongle" ); + s = DO_UPCAST(struct USBBtState, dev, dev); s->dev.opaque = s; - s->dev.speed =USB_SPEED_HIGH ; - s->dev.handle_packet = usb_generic_handle_packet; -pstrcpy (s->dev.devname,sizeof (s->dev.devname),"QEMU BT dongle" ); - - s->dev.handle_reset = usb_bt_handle_reset; - s->dev.handle_control = usb_bt_handle_control; - s->dev.handle_data = usb_bt_handle_data; - s->dev.handle_destroy = usb_bt_handle_destroy; s->hci = hci; s->hci->opaque = s;
@@ -642,5 +642,22 @@ USBDevice *usb_bt_init(HCIInfo *hci)usb_bt_handle_reset (&s->dev); -return &s->dev; +return dev; +} + +static struct USBDeviceInfo bt_info = { + .qdev.name ="QEMU BT dongle" , + .qdev.size =sizeof (struct USBBtState ), + .init = usb_bt_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = usb_bt_handle_reset, + .handle_control = usb_bt_handle_control, + .handle_data = usb_bt_handle_data, + .handle_destroy = usb_bt_handle_destroy, +}; + +static void usb_bt_register_devices (void ) +{ +usb_qdev_register (&bt_info,1 ); } +device_init (usb_bt_register_devices)
hw/usb-bus.c new file +61 -0
61 lines not on this page · raw message
hw/usb-hid.c +59 -44
127 lines not on this page · raw message
hw/usb-hub.c +28 -20
67 lines not on this page · raw message
hw/usb-msd.c +29 -15
70 lines not on this page · raw message
hw/usb-musb.c +1 -1
@@ -591,7 +591,7 @@ static inline void musb_packet(MUSBState *s, MUSBEndPoint *ep, ep->packey[dir].complete_opaque = ep;if (s->port.dev) - ret = s->port.dev->handle_packet (s->port.dev, &ep->packey[dir]); + ret = s->port.dev->info->handle_packet (s->port.dev, &ep->packey[dir]);else ret =USB_RET_NODEV ;
hw/usb-net.c +31 -13
66 lines not on this page · raw message
hw/usb-ohci.c +2 -2
@@ -755,7 +755,7 @@ static int ohci_service_iso_td(OHCIState *ohci, struct ohci_ed *ed, ohci->usb_packet.len = len; ohci->usb_packet.complete_cb = ohci_async_complete_packet; ohci->usb_packet.complete_opaque = ohci; - ret = dev->handle_packet (dev, &ohci->usb_packet); + ret = dev->info->handle_packet (dev, &ohci->usb_packet);if (ret !=USB_RET_NODEV )break ; }
@@ -945,7 +945,7 @@ static int ohci_service_td(OHCIState *ohci, struct ohci_ed *ed) ohci->usb_packet.len = len; ohci->usb_packet.complete_cb = ohci_async_complete_packet; ohci->usb_packet.complete_opaque = ohci; - ret = dev->handle_packet (dev, &ohci->usb_packet); + ret = dev->info->handle_packet (dev, &ohci->usb_packet);if (ret !=USB_RET_NODEV )break ; }
hw/usb-serial.c +31 -16
71 lines not on this page · raw message
hw/usb-uhci.c +3 -1
@@ -122,6 +122,7 @@ typedef struct UHCIPort { typedef struct UHCIState { PCIDevice dev; + USBBus *bus; uint16_t cmd; /* cmd register */ uint16_t status; uint16_t intr; /* interrupt enable register */
@@ -659,7 +660,7 @@ static int uhci_broadcast_packet(UHCIState *s, USBPacket *p)USBDevice *dev = port->port.dev;if (dev && (port->ctrl &UHCI_PORT_EN )) - ret = dev->handle_packet (dev, p); + ret = dev->info->handle_packet (dev, p); }dprintf ("uhci: packet exit. ret %d len %d\n" , ret, p->len);
@@ -1093,6 +1094,7 @@ static void usb_uhci_common_initfn(UHCIState *s)pci_register_bar (&s->dev,4 ,0x20 ,PCI_ADDRESS_SPACE_IO , uhci_map); + s->bus =usb_bus_new (&s->dev.qdev);register_savevm ("uhci" ,0 ,1 , uhci_save, uhci_load, s); }
hw/usb-wacom.c +21 -12
@@ -392,21 +392,30 @@ static void usb_wacom_handle_destroy(USBDevice *dev)qemu_free (s); } -USBDevice *usb_wacom_init (void ) +static void usb_wacom_initfn (USBDevice *dev) { -USBWacomState *s; - - s =qemu_mallocz (sizeof (USBWacomState)); +USBWacomState *s =DO_UPCAST (USBWacomState, dev, dev); s->dev.speed =USB_SPEED_FULL ; - s->dev.handle_packet = usb_generic_handle_packet; +} - s->dev.handle_reset = usb_wacom_handle_reset; - s->dev.handle_control = usb_wacom_handle_control; - s->dev.handle_data = usb_wacom_handle_data; - s->dev.handle_destroy = usb_wacom_handle_destroy; +USBDevice *usb_wacom_init (void ) +{ +return usb_create_simple (NULL /* FIXME */ ,"QEMU PenPartner Tablet" ); +} -pstrcpy (s->dev.devname,sizeof (s->dev.devname), -"QEMU PenPartner Tablet" ); +static struct USBDeviceInfo wacom_info = { + .qdev.name ="QEMU PenPartner Tablet" , + .qdev.size =sizeof (USBWacomState), + .init = usb_wacom_initfn, + .handle_packet = usb_generic_handle_packet, + .handle_reset = usb_wacom_handle_reset, + .handle_control = usb_wacom_handle_control, + .handle_data = usb_wacom_handle_data, + .handle_destroy = usb_wacom_handle_destroy, +}; -return (USBDevice *) s; +static void usb_wacom_register_devices (void ) +{ +usb_qdev_register (&wacom_info,1 ); } +device_init (usb_wacom_register_devices)
hw/usb.c +8 -8
@@ -59,8 +59,8 @@ static int do_token_setup(USBDevice *s, USBPacket *p) index = (s->setup_buf[5 ] <<8 ) | s->setup_buf[4 ];if (s->setup_buf[0 ] &USB_DIR_IN ) { - ret = s->handle_control (s, request, value, index, - s->setup_len, s->data_buf); + ret = s->info->handle_control (s, request, value, index, + s->setup_len, s->data_buf);if (ret <0 )return ret;
@@ -83,7 +83,7 @@ static int do_token_in(USBDevice *s, USBPacket *p)int ret =0 ;if (p->devep !=0 ) -return s->handle_data (s, p); +return s->info->handle_data (s, p); request = (s->setup_buf[0 ] <<8 ) | s->setup_buf[1 ]; value = (s->setup_buf[3 ] <<8 ) | s->setup_buf[2 ];
@@ -93,8 +93,8 @@ static int do_token_in(USBDevice *s, USBPacket *p)case SETUP_STATE_ACK :if (!(s->setup_buf[0 ] &USB_DIR_IN )) { s->setup_state =SETUP_STATE_IDLE ; - ret = s->handle_control (s, request, value, index, - s->setup_len, s->data_buf); + ret = s->info->handle_control (s, request, value, index, + s->setup_len, s->data_buf);if (ret >0 )return 0 ;return ret;
@@ -126,7 +126,7 @@ static int do_token_in(USBDevice *s, USBPacket *p)static int do_token_out (USBDevice *s,USBPacket *p) {if (p->devep !=0 ) -return s->handle_data (s, p); +return s->info->handle_data (s, p);switch (s->setup_state) {case SETUP_STATE_ACK :
@@ -179,7 +179,7 @@ int usb_generic_handle_packet(USBDevice *s, USBPacket *p) s->remote_wakeup =0 ; s->addr =0 ; s->state =USB_STATE_DEFAULT ; - s->handle_reset (s); + s->info->handle_reset (s);return 0 ; }
@@ -225,7 +225,7 @@ void usb_send_msg(USBDevice *dev, int msg)USBPacket p;memset (&p,0 ,sizeof (p)); p.pid = msg; - dev->handle_packet (dev, &p); + dev->info->handle_packet (dev, &p);/* This _must_ be synchronous */ }
hw/usb.h +38 -23
101 lines not on this page · raw message
usb-linux.c +36 -16
97 lines not on this page · raw message
vl.c +2 -2
@@ -2655,7 +2655,7 @@ static void usb_msd_password_cb(void *opaque, int err)if (!err)usb_device_add_dev (dev);else - dev->handle_destroy (dev); + dev->info->handle_destroy (dev); }static int usb_device_add (const char *devname,int is_hotplug)
@@ -2741,7 +2741,7 @@ int usb_device_del_addr(int bus_num, int addr) dev = port->dev; *lastp = port->next;usb_attach (port,NULL ); - dev->handle_destroy (dev); + dev->info->handle_destroy (dev); port->next = free_usb_ports; free_usb_ports = port;return 0 ;
Signature · 1 line
1.6.2.2
PATCH 10/10 qdev-ify: scsi
In reply to Gerd Hoffmann--- Makefile | 2 +- hw/esp.c | 28 +++++++++++---------- hw/lsi53c895a.c | 31 +++++++++++++---------- hw/qdev.c | 19 -------------- hw/qdev.h | 4 --- hw/scsi-bus.c | 65 +++++++++++++++++++++++++++++++++++++++++++++++++ hw/scsi-disk.c | 69 ++++++++++++++++++++++++++++++++-------------------- hw/scsi-disk.h | 49 +++++++++++++++++++++++++++++++------ hw/scsi-generic.c | 62 ++++++++++++++++++++++++++++++----------------- hw/usb-msd.c | 24 ++++++++++-------- 10 files changed, 233 insertions(+), 120 deletions(-) create mode 100644 hw/scsi-bus.c
Makefile +1 -1
@@ -100,7 +100,7 @@ OBJS+=i2c.o smbus.o smbus_eeprom.o max7310.o max111x.o wm8750.o OBJS+=ssd0303.o ssd0323.o ads7846.o stellaris_input.o twl92230.o OBJS+=tmp105.o lm832x.o eeprom93xx.o tsc2005.o OBJS+=scsi-disk.o cdrom.o -OBJS+=scsi-generic.o +OBJS+=scsi-generic.o scsi-bus.o OBJS+=usb.o usb-hub.o usb-$(HOST_USB).o usb-hid.o usb-msd.o usb-wacom.o OBJS+=usb-serial.o usb-net.o usb-bus.o OBJS+=sd.o ssi-sd.o
hw/esp.c +15 -13
@@ -63,6 +63,7 @@ struct ESPState {uint8_t ti_buf[TI_BUFSZ ];uint32_t sense;uint32_t dma; +SCSIBus *bus;SCSIDevice *scsi_dev[ESP_MAX_DEVS ];SCSIDevice *current_dev;uint8_t cmdbuf[TI_BUFSZ ];
@@ -185,7 +186,7 @@ static uint32_t get_cmd(ESPState *s, uint8_t *buf)if (s->current_dev) {/* Started a new command before the old one finished. Cancel it. */ - s->current_dev->cancel_io (s->current_dev,0 ); + s->current_dev->info->cancel_io (s->current_dev,0 ); s->async_len =0 ; }
@@ -208,7 +209,7 @@ static void do_cmd(ESPState *s, uint8_t *buf)DPRINTF ("do_cmd: busid 0x%x\n" , buf[0 ]); lun = buf[0 ] &7 ; - datalen = s->current_dev->send_command (s->current_dev,0 , &buf[1 ], lun); + datalen = s->current_dev->info->send_command (s->current_dev,0 , &buf[1 ], lun); s->ti_size = datalen;if (datalen !=0 ) { s->rregs[ESP_RSTAT ] =STAT_TC ;
@@ -216,10 +217,10 @@ static void do_cmd(ESPState *s, uint8_t *buf) s->dma_counter =0 ;if (datalen >0 ) { s->rregs[ESP_RSTAT ] |=STAT_DI ; - s->current_dev->read_data (s->current_dev,0 ); + s->current_dev->info->read_data (s->current_dev,0 ); }else { s->rregs[ESP_RSTAT ] |=STAT_DO ; - s->current_dev->write_data (s->current_dev,0 ); + s->current_dev->info->write_data (s->current_dev,0 ); } } s->rregs[ESP_RINTR ] =INTR_BS |INTR_FC ;
@@ -318,9 +319,9 @@ static void esp_do_dma(ESPState *s)if (s->async_len ==0 ) {if (to_device) {// ti_size is negative - s->current_dev->write_data (s->current_dev,0 ); + s->current_dev->info->write_data (s->current_dev,0 ); }else { - s->current_dev->read_data (s->current_dev,0 ); + s->current_dev->info->read_data (s->current_dev,0 );/* If there is still data to be read from the device then complete the DMA operation immediately. Otherwise defer until the scsi layer has completed. */
@@ -334,10 +335,10 @@ static void esp_do_dma(ESPState *s) } } -static void esp_command_complete (void *opaque,int reason,uint32_t tag, +static void esp_command_complete (SCSIBus *bus,int reason,uint32_t tag,uint32_t arg) { -ESPState *s = (ESPState *)opaque; +ESPState *s =DO_UPCAST (ESPState, busdev.qdev, bus->qbus.parent);if (reason ==SCSI_REASON_DONE ) {DPRINTF ("SCSI Command complete\n" );
@@ -355,7 +356,7 @@ static void esp_command_complete(void *opaque, int reason, uint32_t tag, }else {DPRINTF ("transfer %d/%d\n" , s->dma_left, s->ti_size); s->async_len = arg; - s->async_buf = s->current_dev->get_buf (s->current_dev,0 ); + s->async_buf = s->current_dev->info->get_buf (s->current_dev,0 );if (s->dma_left) {esp_do_dma (s); }else if (s->dma_counter !=0 && s->ti_size <=0 ) {
@@ -636,13 +637,13 @@ static void esp_scsi_attach(DeviceState *host, BlockDriverState *bd, int id) }if (s->scsi_dev[id]) {DPRINTF ("Destroying device %d\n" , id); - s->scsi_dev[id]->destroy (s->scsi_dev[id]); + s->scsi_dev[id]->info->destroy (s->scsi_dev[id]); }DPRINTF ("Attaching block device %d\n" , id);/* Command queueing is not implemented. */ - s->scsi_dev[id] =scsi_generic_init (bd,0 , esp_command_complete, s); + s->scsi_dev[id] =scsi_generic_init (s->bus, bd);if (s->scsi_dev[id] ==NULL ) - s->scsi_dev[id] =scsi_disk_init (bd,0 , esp_command_complete, s); + s->scsi_dev[id] =scsi_disk_init (s->bus, bd); } void esp_init(target_phys_addr_t espaddr, int it_shift,
@@ -686,7 +687,8 @@ static void esp_init1(SysBusDevice *dev)qdev_init_gpio_in (&dev->qdev, parent_esp_reset,1 ); -scsi_bus_new (&dev->qdev, esp_scsi_attach); + s->bus =scsi_bus_new (&dev->qdev,0 , esp_scsi_attach, esp_command_complete); +scsi_bus_attach_cmdline (s->bus); }static void esp_register_devices (void )
hw/lsi53c895a.c +17 -14
@@ -12,6 +12,7 @@#include "hw.h" #include "pci.h" +#include "scsi.h" #include "scsi-disk.h" #include "block_int.h"
@@ -190,6 +191,7 @@ typedef struct {* 2 if processing DMA from lsi_execute_script. * 3 if a DMA operation is in progress. */ int waiting; +SCSIBus *bus;SCSIDevice *scsi_dev[LSI_MAX_DEVS ];SCSIDevice *current_dev;int current_lun;
@@ -508,8 +510,8 @@ static void lsi_do_dma(LSIState *s, int out) s->dbc -= count;if (s->dma_buf ==NULL ) { - s->dma_buf = s->current_dev->get_buf (s->current_dev, - s->current_tag); + s->dma_buf = s->current_dev->info->get_buf (s->current_dev, + s->current_tag); }/* ??? Set SFBR to first data byte. */
@@ -523,10 +525,10 @@ static void lsi_do_dma(LSIState *s, int out) s->dma_buf =NULL ;if (out) {/* Write the data. */ - s->current_dev->write_data (s->current_dev, s->current_tag); + s->current_dev->info->write_data (s->current_dev, s->current_tag); }else {/* Request any remaining data. */ - s->current_dev->read_data (s->current_dev, s->current_tag); + s->current_dev->info->read_data (s->current_dev, s->current_tag); } }else { s->dma_buf += count;
@@ -630,10 +632,10 @@ static int lsi_queue_tag(LSIState *s, uint32_t tag, uint32_t arg) }/* Callback to indicate that the SCSI layer has completed a transfer. */ -static void lsi_command_complete (void *opaque,int reason,uint32_t tag, +static void lsi_command_complete (SCSIBus *bus,int reason,uint32_t tag,uint32_t arg) { -LSIState *s = (LSIState *)opaque; +LSIState *s =DO_UPCAST (LSIState, pci_dev.qdev, bus->qbus.parent);int out; out = (s->sstat1 &PHASE_MASK ) ==PHASE_DO ;
@@ -678,14 +680,14 @@ static void lsi_do_command(LSIState *s)cpu_physical_memory_read (s->dnad, buf, s->dbc); s->sfbr = buf[0 ]; s->command_complete =0 ; - n = s->current_dev->send_command (s->current_dev, s->current_tag, buf, - s->current_lun); + n = s->current_dev->info->send_command (s->current_dev, s->current_tag, buf, + s->current_lun);if (n >0 ) {lsi_set_phase (s,PHASE_DI ); - s->current_dev->read_data (s->current_dev, s->current_tag); + s->current_dev->info->read_data (s->current_dev, s->current_tag); }else if (n <0 ) {lsi_set_phase (s,PHASE_DO ); - s->current_dev->write_data (s->current_dev, s->current_tag); + s->current_dev->info->write_data (s->current_dev, s->current_tag); }if (!s->command_complete) {
@@ -1972,12 +1974,12 @@ void lsi_scsi_attach(DeviceState *host, BlockDriverState *bd, int id) }if (s->scsi_dev[id]) {DPRINTF ("Destroying device %d\n" , id); - s->scsi_dev[id]->destroy (s->scsi_dev[id]); + s->scsi_dev[id]->info->destroy (s->scsi_dev[id]); }DPRINTF ("Attaching block device %d\n" , id); - s->scsi_dev[id] =scsi_generic_init (bd,1 , lsi_command_complete, s); + s->scsi_dev[id] =scsi_generic_init (s->bus, bd);if (s->scsi_dev[id] ==NULL ) - s->scsi_dev[id] =scsi_disk_init (bd,1 , lsi_command_complete, s); + s->scsi_dev[id] =scsi_disk_init (s->bus, bd); bd->private = &s->pci_dev; }
@@ -2032,7 +2034,8 @@ static void lsi_scsi_init(PCIDevice *dev)lsi_soft_reset (s); -scsi_bus_new (&dev->qdev, lsi_scsi_attach); + s->bus =scsi_bus_new (&dev->qdev,1 , lsi_scsi_attach, lsi_command_complete); +scsi_bus_attach_cmdline (s->bus); }static PCIDeviceInfo lsi_info = {
hw/qdev.c +0 -19
@@ -288,25 +288,6 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name)return NULL ; } -static int next_scsi_bus; - -/* Create a scsi bus, and attach devices to it. */ -/* TODO: Actually create a scsi bus for hotplug to use. */ -void scsi_bus_new (DeviceState *host,SCSIAttachFn attach) -{ -int bus = next_scsi_bus++; -int unit; -int index; - -for (unit =0 ; unit <MAX_SCSI_DEVS ; unit++) { - index =drive_get_index (IF_SCSI , bus, unit); -if (index ==-1 ) { -continue ; - } -attach (host, drives_table[index].bdrv, unit); - } -} -BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name) {BusState *bus;
hw/qdev.h +0 -4
@@ -73,8 +73,6 @@ typedef struct { } DevicePropList;typedef void (*qdev_initfn )(DeviceState *dev,DeviceInfo *info); -typedef void (*SCSIAttachFn )(DeviceState *host,BlockDriverState *bdrv, -int unit);struct DeviceInfo {const char *name;
@@ -94,8 +92,6 @@ void qdev_register(DeviceInfo *info);void qdev_init_gpio_in (DeviceState *dev,qemu_irq_handler handler,int n);void qdev_init_gpio_out (DeviceState *dev,qemu_irq *pins,int n); -void scsi_bus_new (DeviceState *host,SCSIAttachFn attach); -CharDriverState *qdev_init_chardev (DeviceState *dev);BusState *qdev_get_parent_bus (DeviceState *dev);
hw/scsi-bus.c new file +65 -0
65 lines not on this page · raw message
hw/scsi-disk.c +42 -27
163 lines not on this page · raw message
hw/scsi-disk.h +41 -8
74 lines not on this page · raw message
hw/scsi-generic.c +39 -23
161 lines not on this page · raw message
hw/usb-msd.c +13 -11
@@ -44,6 +44,7 @@ typedef struct {uint32_t residue;uint32_t tag;BlockDriverState *bs; +SCSIBus *bus;SCSIDevice *scsi_dev;int result;/* For async completion. */
@@ -150,9 +151,9 @@ static void usb_msd_copy_data(MSDState *s) s->data_len -= len;if (s->scsi_len ==0 ) {if (s->mode ==USB_MSDM_DATAIN ) { - s->scsi_dev->read_data (s->scsi_dev, s->tag); + s->scsi_dev->info->read_data (s->scsi_dev, s->tag); }else if (s->mode ==USB_MSDM_DATAOUT ) { - s->scsi_dev->write_data (s->scsi_dev, s->tag); + s->scsi_dev->info->write_data (s->scsi_dev, s->tag); } } }
@@ -168,10 +169,10 @@ static void usb_msd_send_status(MSDState *s)memcpy (s->usb_buf, &csw,13 ); } -static void usb_msd_command_complete (void *opaque,int reason,uint32_t tag, +static void usb_msd_command_complete (SCSIBus *bus,int reason,uint32_t tag,uint32_t arg) { -MSDState *s = (MSDState *)opaque; +MSDState *s =DO_UPCAST (MSDState, dev.qdev, bus->qbus.parent);USBPacket *p = s->packet;if (tag != s->tag) {
@@ -205,7 +206,7 @@ static void usb_msd_command_complete(void *opaque, int reason, uint32_t tag,return ; } s->scsi_len = arg; - s->scsi_buf = s->scsi_dev->get_buf (s->scsi_dev, tag); + s->scsi_buf = s->scsi_dev->info->get_buf (s->scsi_dev, tag);if (p) {usb_msd_copy_data (s);if (s->usb_len ==0 ) {
@@ -343,7 +344,7 @@ static int usb_msd_handle_control(USBDevice *dev, int request, int value,static void usb_msd_cancel_io (USBPacket *p,void *opaque) {MSDState *s = opaque; - s->scsi_dev->cancel_io (s->scsi_dev, s->tag); + s->scsi_dev->info->cancel_io (s->scsi_dev, s->tag); s->packet =NULL ; s->scsi_len =0 ; }
@@ -391,14 +392,14 @@ static int usb_msd_handle_data(USBDevice *dev, USBPacket *p)DPRINTF ("Command tag 0x%x flags %08x len %d data %d\n" , s->tag, cbw.flags, cbw.cmd_len, s->data_len); s->residue =0 ; - s->scsi_dev->send_command (s->scsi_dev, s->tag, cbw.cmd,0 ); + s->scsi_dev->info->send_command (s->scsi_dev, s->tag, cbw.cmd,0 );/* ??? Should check that USB and SCSI data transfer directions match. */ if (s->residue ==0 ) {if (s->mode ==USB_MSDM_DATAIN ) { - s->scsi_dev->read_data (s->scsi_dev, s->tag); + s->scsi_dev->info->read_data (s->scsi_dev, s->tag); }else if (s->mode ==USB_MSDM_DATAOUT ) { - s->scsi_dev->write_data (s->scsi_dev, s->tag); + s->scsi_dev->info->write_data (s->scsi_dev, s->tag); } } ret = len;
@@ -509,7 +510,7 @@ static void usb_msd_handle_destroy(USBDevice *dev) {MSDState *s = (MSDState *)dev; - s->scsi_dev->destroy (s->scsi_dev); + s->scsi_dev->info->destroy (s->scsi_dev);bdrv_delete (s->bs);qemu_free (s); }
@@ -566,7 +567,8 @@ USBDevice *usb_msd_init(const char *filename)snprintf (s->dev.devname,sizeof (s->dev.devname),"QEMU USB MSD(%.16s)" , filename); - s->scsi_dev =scsi_disk_init (bdrv,0 , usb_msd_command_complete, s); + s->bus =scsi_bus_new (&s->dev.qdev,0 ,NULL , usb_msd_command_complete); + s->scsi_dev =scsi_disk_init (s->bus, bdrv);usb_msd_handle_reset ((USBDevice *)s);return (USBDevice *)s; }
Signature · 1 line
1.6.2.2
Hi,
Quoted 2 lines
The patches can also be pulled from
git://git.et.redhat.com/qemu-kraxel.git(branch qdev.v4).
Updated patch queue pushed to qdev.v5. Not posting to avoid spamming the list too much. Online viewable via gitweb here:
http://git.et.redhat.com/?p=qemu-kraxel.git;a=shortlog;h=refs/heads/qdev.v5
Changes:
* bunch of minor fixes and improvements.
* more verbose commit messages.
* more usb work, teach qemu about busses, it can deal with more than one usb bus now.
enjoy,
Gerd
Hi,
Quoted 3 lines
Updated patch queue pushed to qdev.v5. Not posting to avoid spamming the list too much. Online viewable via gitweb here:
http://git.et.redhat.com/?p=qemu-kraxel.git;a=shortlog;h=refs/heads/qdev.v5
Todays update pushed to qdev.v6.
http://git.et.redhat.com/?p=qemu-kraxel.git;a=shortlog;h=refs/heads/qdev.v6
Changes:
* Reordered patches:
- First the patches with the core changes.
- Then conversion of some PCI drivers.
- Next USB.
- Next SCSI.
- Finally some test patches I've used to play with multiple USB busses.
The core patches are needed for all others. The usb-related patches build on each other and must be applied in order. SCSI goes after USB because of usb-storage. Otherwise the patches should be independent on each other.
* Converted VGA drivers and ac97/es1370 to qdev.
* Minor tweaks.
cheers,
Gerd
Quoted 9 lines · Gerd Hoffmann
Hi,Quoted 4 lines
Updated patch queue pushed to qdev.v5. Not posting to avoid spamming the list too much. Online viewable via gitweb here:
http://git.et.redhat.com/?p=qemu-kraxel.git;a=shortlog;h=refs/heads/qdev.
v5Todays update pushed to qdev.v6.
http://git.et.redhat.com/?p=qemu-kraxel.git;a=shortlog;h=refs/heads/qdev.v6
A few comments on specific patches:
* qdev: update pci device registration
I dislike passing an {array,length} pair. Especially when it requires every user to manually get the right length.
* qdev/core: bus list
I don't seen any good reason for this. In fact I think it is a major step backwards. A bus is uniquely identified by its name and parent device.
* qdev/pci: misc fixes.
All uses of the second argument to savevm should go away, not introduce new ones. I'm unconvinced by the dev->name change. If we're using the same value then why does it exist at all?
* qdev/pci: hook up i440fx
i440fx_init should not exist. c.f. versatile_pci.c
* qdev: update pci device registration
This is exactly the sort of fake conversion that I don't like, because you still require use of the old hardcoded initialization functions. Convenience wrappers like smc91c111_init are fine (and will naturally disappear when we have a machine config), but you shouldn't be poking directly at device state.
In practice there's no way for the user to have more than one set of IDE busses, so I don't see much point pretending we allow this. i.e. remove the hd_table argument altogether and use drive_get_index directly.
* qdev: convert all vga
Likewise, pci_vga_init needs to go away.
* qdev/scsi: add scsi bus support to qdev, convert drivers
This still feels wrong, probably because you're using the same thing for both a parallel scsi bus, and for devices (usb-msd) that incorporate scsi functionality directly. The current qemu scsi API is actually a set of point to point links with individual devices. All the bus emulation is local to the host controller.
* qdev/usb*
I have not looked at these patches.
Quoted 4 lines · Paul Brook
* qdev: update pci device registration
I dislike passing an {array,length} pair. Especially when it requires every user to manually get the right length.
qemu has a ARRAY_SIZE macro which can be used like this:
(from uhci patch):
pci_qdev_register(uhci_info, ARRAY_SIZE(uhci_info));
to get the right length, so I don't see this as a problem.
I can create pci_qdev_register_{single,array} macros to hide the length parameter. I can also just drop the length argument and just use multiple calls in the (few) places where multiple drivers are registered at once. What do you prefer?
Quoted 4 lines
* qdev/core: bus list
I don't seen any good reason for this. In fact I think it is a major step backwards. A bus is uniquely identified by its name and parent device.
For a static device tree you don't need that indeed. I've added the patch recently while hacking usb, the reason is hotplugging devices. When adding devices to busses using monitor commands you'll need some way to specify the bus and to find it. This gets the job done without having to walk the whole device tree.
Quoted 4 lines
* qdev/pci: misc fixes.
All uses of the second argument to savevm should go away, not introduce new ones.
This just maintains current behavior (PCI busses are numbered starting zero).
Quoted 2 lines
I'm unconvinced by the
dev->namechange. If we're using the same value then why does it exist at all?
It is redundant indeed. I've considered dropping it right away, then decided to better wait with that step until all PCI drivers are converted to qdev.
Quoted 3 lines
* qdev/pci: hook up i440fx
i440fx_initshould not exist. c.f.versatile_pci.c
Indeed. That is the long-term plan, I'm just not there yet.
Quoted 1 line
* qdev: update pci device registration
Guess this was supposed to say "qdev: convert piix-ide." ?
Quoted 2 lines
This is exactly the sort of fake conversion that I don't like, because you still require use of the old hardcoded initialization functions.
I'd prefer to call them "incomplete" instead of "fake". I know that more work needs to be done to get the drivers into shape for a dt-driven machine creation.
Quoted 1 line
Convenience wrappers like
smc91c111_initare fine
Yes, that is the plan for all drivers. So the old, hardcoded way of doing things keeps working while we are busy making the dt-driven machine creation work.
I'm just not there yet in all cases. Basically every old *_init() call which has more than a single $bus_create_simple(...) call needs more work.
cheers,
Gerd
Quoted 6 lines · Gerd Hoffmann
Quoted 4 lines · Paul Brook
* qdev: update pci device registration
I dislike passing an {array,length} pair. Especially when it requires every user to manually get the right length.
Quoted 8 lines
qemu has a
ARRAY_SIZEmacro which can be used like this:
(from uhci patch):pci_qdev_register(uhci_info, ARRAY_SIZE(uhci_info));to get the right length, so I don't see this as a problem.
I can create pci_qdev_register_{single,array} macros to hide the length parameter. I can also just drop the length argument and just use multiple calls in the (few) places where multiple drivers are registered at once. What do you prefer?
There's a third alternative, zero terminating the array.
If most calls register one qdev, I'd prefer pci_qdev_register() and pci_qdev_register_many().
Signature · 1 line
error compiling committee.c: too many arguments to function
Quoted 10 lines · Avi Kivity
Quoted 4 lines · Gerd Hoffmann
I can create pci_qdev_register_{single,array} macros to hide the length parameter. I can also just drop the length argument and just use multiple calls in the (few) places where multiple drivers are registered at once. What do you prefer?
There's a third alternative, zero terminating the array.
If most calls register one qdev, I'd prefer
pci_qdev_register()andpci_qdev_register_many().
Where register() takes a single instance and register_many() a zero-terminated array I guess? Sounds good.
cheers,
Gerd
Quoted 8 lines · Gerd Hoffmann
Quoted 4 lines · Avi Kivity
There's a third alternative, zero terminating the array.
If most calls register one qdev, I'd prefer
pci_qdev_register()andpci_qdev_register_many().Where
register()takes a single instance andregister_many()a zero-terminated array I guess? Sounds good.
i.e. something like the attached patch (incremental to the whole patch series).
cheers,
Gerd
hw/ac97.c +1 -1
@@ -1373,7 +1373,7 @@ static PCIDeviceInfo ac97_info = {static void ac97_register (void ) { -pci_qdev_register (&ac97_info,1 ); +pci_qdev_register (&ac97_info); }device_init (ac97_register);
hw/acpi.c +1 -1
@@ -573,7 +573,7 @@ static PCIDeviceInfo acpi_info = {static void acpi_register (void ) { -pci_qdev_register (&acpi_info,1 ); +pci_qdev_register (&acpi_info); }device_init (acpi_register);
hw/cirrus_vga.c +1 -1
@@ -3350,6 +3350,6 @@ static PCIDeviceInfo cirrus_vga_info = {static void cirrus_vga_register (void ) { -pci_qdev_register (&cirrus_vga_info,1 ); +pci_qdev_register (&cirrus_vga_info); }device_init (cirrus_vga_register);
hw/e1000.c +1 -1
@@ -1133,7 +1133,7 @@ static PCIDeviceInfo e1000_info = {static void e1000_register_devices (void ) { -pci_qdev_register (&e1000_info,1 ); +pci_qdev_register (&e1000_info); }device_init (e1000_register_devices)
hw/eepro100.c +3 -1
@@ -1805,12 +1805,14 @@ static PCIDeviceInfo eepro100_info[] = { .qdev.name = "i82559er", .qdev.size = sizeof(PCIEEPRO100State), .init = pci_i82559er_init, + },{ +/* end of list */ } };static void eepro100_register_devices (void ) { -pci_qdev_register (eepro100_info,ARRAY_SIZE (eepro100_info)); +pci_qdev_register_many (eepro100_info); }device_init (eepro100_register_devices)
hw/es1370.c +1 -1
@@ -1060,7 +1060,7 @@ static PCIDeviceInfo es1370_info = {static void es1370_register (void ) { -pci_qdev_register (&es1370_info,1 ); +pci_qdev_register (&es1370_info); }device_init (es1370_register);
hw/ide.c +3 -1
@@ -3456,12 +3456,14 @@ static PCIDeviceInfo piix_ide_info[] = { .qdev.name = "PIIX4 IDE", .qdev.size = sizeof(PCIIDEState), .init = pci_piix4_ide_initfn, + },{ +/* end of list */ } };static void piix_ide_register (void ) { -pci_qdev_register (piix_ide_info,ARRAY_SIZE (piix_ide_info)); +pci_qdev_register_many (piix_ide_info); }device_init (piix_ide_register);
hw/lsi53c895a.c +1 -1
@@ -2046,7 +2046,7 @@ static PCIDeviceInfo lsi_info = {static void lsi53c895a_register_devices (void ) { -pci_qdev_register (&lsi_info,1 ); +pci_qdev_register (&lsi_info); }device_init (lsi53c895a_register_devices);
hw/ne2000.c +1 -1
@@ -840,7 +840,7 @@ static PCIDeviceInfo ne2000_info = {static void ne2000_register_devices (void ) { -pci_qdev_register (&ne2000_info,1 ); +pci_qdev_register (&ne2000_info); }device_init (ne2000_register_devices)
hw/pci.c +10 -6
@@ -921,14 +921,18 @@ static void pci_qdev_init(DeviceState *qdev, DeviceInfo *base) info->init (pci_dev); } -void pci_qdev_register (PCIDeviceInfo *info,int count) +void pci_qdev_register (PCIDeviceInfo *info) { -int i; + info->qdev.init = pci_qdev_init; + info->qdev.bus_info = &pci_bus_info; +qdev_register (&info->qdev); +} -for (i =0 ; i < count; i++, info++) { - info->qdev.init = pci_qdev_init; - info->qdev.bus_info = &pci_bus_info; -qdev_register (&info->qdev); +void pci_qdev_register_many (PCIDeviceInfo *info) +{ +while (info->qdev.name) { +pci_qdev_register (info); + info++; } }
hw/pci.h +2 -1
@@ -225,7 +225,8 @@ typedef struct {PCIConfigWriteFunc *config_write; } PCIDeviceInfo; -void pci_qdev_register (PCIDeviceInfo *info,int count); +void pci_qdev_register (PCIDeviceInfo *info); +void pci_qdev_register_many (PCIDeviceInfo *info);PCIDevice *pci_create_simple (PCIBus *bus,int devfn,const char *name);
hw/pcnet.c +1 -1
@@ -2151,7 +2151,7 @@ static PCIDeviceInfo pcnet_info = {static void pcnet_register_devices (void ) { -pci_qdev_register (&pcnet_info,1 ); +pci_qdev_register (&pcnet_info);#if defined (TARGET_SPARC ) && !defined(TARGET_SPARC64 )sysbus_register_dev ("lance" ,sizeof (SysBusPCNetState), lance_init);#endif
hw/piix_pci.c +3 -1
@@ -404,12 +404,14 @@ static PCIDeviceInfo i440fx_info[] = { .qdev.name = "PIIX4", .qdev.size = sizeof(PCIDevice), .init = piix4_initfn, + },{ +/* end of list */ } };static void i440fx_register (void ) {sysbus_register_dev ("i440FX-pcihost" ,sizeof (I440FXState), i440fx_pcihost_initfn); -pci_qdev_register (i440fx_info,ARRAY_SIZE (i440fx_info)); +pci_qdev_register_many (i440fx_info); }device_init (i440fx_register);
hw/rtl8139.c +1 -1
@@ -3507,7 +3507,7 @@ static PCIDeviceInfo rtl8139_info = {static void rtl8139_register_devices (void ) { -pci_qdev_register (&rtl8139_info,1 ); +pci_qdev_register (&rtl8139_info); }device_init (rtl8139_register_devices)
hw/usb-ohci.c +1 -1
@@ -1771,6 +1771,6 @@ static PCIDeviceInfo ohci_info = {static void ohci_register (void ) { -pci_qdev_register (&ohci_info,1 ); +pci_qdev_register (&ohci_info); }device_init (ohci_register);
hw/usb-uhci.c +3 -1
@@ -1129,12 +1129,14 @@ static PCIDeviceInfo uhci_info[] = { .qdev.name = "PIIX4 USB-UHCI", .qdev.size = sizeof(UHCIState), .init = usb_uhci_piix4_initfn, + },{ +/* end of list */ } };static void uhci_register (void ) { -pci_qdev_register (uhci_info,ARRAY_SIZE (uhci_info)); +pci_qdev_register_many (uhci_info); }device_init (uhci_register);
hw/versatile_pci.c +1 -1
@@ -164,7 +164,7 @@ static void versatile_pci_register_devices(void)sysbus_register_dev ("versatile_pci" ,sizeof (PCIVPBState), pci_vpb_init);sysbus_register_dev ("realview_pci" ,sizeof (PCIVPBState), pci_realview_init); -pci_qdev_register (&versatile_pci_host_info,1 ); +pci_qdev_register (&versatile_pci_host_info); }device_init (versatile_pci_register_devices)
hw/vga.c +1 -1
@@ -2538,7 +2538,7 @@ static PCIDeviceInfo vga_info = {static void vga_register (void ) { -pci_qdev_register (&vga_info,1 ); +pci_qdev_register (&vga_info); }device_init (vga_register);
hw/virtio-pci.c +3 -1
@@ -351,12 +351,14 @@ static PCIDeviceInfo virtio_info[] = { .qdev.name = "virtio-balloon-pci", .qdev.size = sizeof(VirtIOPCIProxy), .init = virtio_balloon_init_pci, + },{ +/* end of list */ } };static void virtio_pci_register_devices (void ) { -pci_qdev_register (virtio_info,ARRAY_SIZE (virtio_info)); +pci_qdev_register_many (virtio_info); }device_init (virtio_pci_register_devices)
hw/vmware_vga.c +1 -1
@@ -1251,6 +1251,6 @@ static PCIDeviceInfo vmsvga_info = {static void vmsvga_register (void ) { -pci_qdev_register (&vmsvga_info,1 ); +pci_qdev_register (&vmsvga_info); }device_init (vmsvga_register);
Quoted 4 lines · Gerd Hoffmann
Quoted 3 lines · Gerd Hoffmann
Quoted 2 lines · Avi Kivity
There's a third alternative, zero terminating the array.
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
If most calls register one qdev, I'd prefer
pci_qdev_register()andpci_qdev_register_many().Where
register()takes a single instance andregister_many()a zero-terminated array I guess? Sounds good.i.e. something like the attached patch (incremental to the whole patch series).
Yes.
Signature · 1 line
error compiling committee.c: too many arguments to function
Hi,
Quoted 7 lines
Quoted 3 lines
This is exactly the sort of fake conversion that I don't like, because you
still require use of the old hardcoded initialization functions.I'd prefer to call them "incomplete" instead of "fake". I know that more work needs to be done to get the drivers into shape for a dt-driven machine creation.
To followup with some more backgroud on that on that: These are cases where additional arguments are passed to the *_init() function.
Partly the reason is irq windup (i.e. passing around qemu_irqs), which must be adapted. Didn't investigate that one yet. Probably non-trivial to the way interrupts work (pic, lapic, ioapic, ...) in PCs.
Partly the arguments carry extra configutation info. In that case the info should probably come as attributes from the the device tree. Didn't look (yet) into using attributes, one of the reasons being that the API for them is still quite unclear.
cheers,
Gerd
Hi,
Quoted 3 lines
In practice there's no way for the user to have more than one set of IDE busses, so I don't see much point pretending we allow this. i.e. remove the
hd_tableargument altogether and usedrive_get_indexdirectly.
I tend to kill the drives_table[] completely. It mixes host and guest state, we need to separate them.
For the host side I think about a linked list built from stripped down DriveInfo which contains the hostside info only (BlockDriverState + friends) and a name to reference it.
The guest side will link to the host side state using the name, probably passed as attribute.
cheers,
Gerd
Quoted 6 lines
The other patches switch over various drivers and busses to qdev. They depend on the first two patches. The conversion work is far from being completed. Currently my main focus is on getting all devices into the qdev tree. Most drivers are not (yet) in a state where creating them from a fdt can actually work though. IMHO the patches are useful nevertheless. YMMV, feel free to cherry-pick some of the patches only.
I'm not so convinced. I don't see much value in "dummy" conversion that still requires use of the old APIs to create devices.
Paul
Quoted 9 lines · Paul Brook
Quoted 6 lines
The other patches switch over various drivers and busses to qdev. They depend on the first two patches. The conversion work is far from being completed. Currently my main focus is on getting all devices into the qdev tree. Most drivers are not (yet) in a state where creating them from a fdt can actually work though. IMHO the patches are useful nevertheless. YMMV, feel free to cherry-pick some of the patches only.
I'm not so convinced. I don't see much value in "dummy" conversion that still requires use of the old APIs to create devices.
What's wrong with merging an intermediate step, as long as it doesn't break anything, clearly moves in the right direction, and the developer can be trusted to go the rest of the way?
Forcing him to keep his substantial patches out of tree until they're perfectly complete just creates merging & rebasing hassle for him, which can only slow him down. Moreover, it keeps his work less visible, and thus risks duplicated effort.