qdev patches.
cover qdev patches.
Hi,
This is a respin of my qdev patches. They are rebased to the latest master. Addressed review comments, partly by changing code, partly by clarifying commit messages.
The first five patches build the groundwork, I'd like to see them merged soon.
The other patches are are converting drivers (pci/scsi/usb) and subsystems (scsi/usb) to qdev. As in the previous submission not all driver conversions are complete, i.e. the ${driver}_init() function does more than wrapping a simple ${bus}_create_simple() call, thus creating the devices from a device tree can't work (yet). I think the patches are useful even for the drivers which are not finished.
The last two patches are just temporary patches to test multiple usb busses.
Next item on my todo list is having a look at the disk setup: separate host / guest state, link them somehow (probably by name using device attributes). That should allow to make qdev conversion progress on the scsi+ide+virtioblk+usbstorage front.
The patches can also be pulled from
git://git.et.redhat.com/qemu-kraxel.git (branch qdev.v7).
cheers,
Gerd
PATCH 3/20 qdev: remove DeviceType
The 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.5
PATCH 4/20 qdev/core: bus list
In reply to Gerd Hoffmann * maintain a list of busses.
* maintain bus numbers.
* add function to find busses by type / name / number.
* add monitor command to list busses.
Use case for the bus list is hot-plugging devices via monitor, where qemu needs some way to find the bus specified in the monitor command. The usb patches in the patch queue make use of this.
--- hw/qdev.c | 41 ++++++++++++++++++++++++++++++++++++++++- hw/qdev.h | 5 +++++ monitor.c | 2 ++ 3 files changed, 47 insertions(+), 1 deletions(-)
hw/qdev.c +40 -1
@@ -306,22 +306,50 @@ void scsi_bus_new(DeviceState *host, SCSIAttachFn attach)attach (host, drives_table[index].bdrv, unit); } } +static TAILQ_HEAD(, BusState) buslist = TAILQ_HEAD_INITIALIZER(buslist);BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name) {BusState *bus; +char buf[32 ]; +int i; bus =qemu_mallocz (info->size); bus->info = info; + bus->busnr = info->next_busnr++; bus->parent = parent; +if (!name) { +/* default name: lowercase(type) + busnr, i.e. "scsi0" */ +snprintf (buf,sizeof (buf),"%s%d" , info->name, bus->busnr); +for (i =0 ; buf[i]; i++) + buf[i] =tolower (buf[i]); + name = buf; + } bus->name =qemu_strdup (name);LIST_INIT (&bus->children);if (parent) {LIST_INSERT_HEAD (&parent->child_bus, bus, sibling); } +TAILQ_INSERT_TAIL (&buslist, bus, next);return bus; } +BusState *qbus_find (const char *type,const char *name,int busnr) +{ +BusState *bus; + + TAILQ_FOREACH(bus, &buslist, next) { +if (type &&strcmp (type, bus->info->name) !=0 ) +continue ; +if (name &&strcmp (name, bus->name) !=0 ) +continue ; +if (busnr !=-1 && busnr != bus->busnr) +continue ; +return bus; + } +return NULL ; +} +#define qdev_printf (fmt, ...) monitor_printf(mon, "%*s" fmt, indent, "", ## __VA_ARGS__)static void qbus_print (Monitor *mon,BusState *bus,int indent);
@@ -368,7 +396,7 @@ static void qbus_print(Monitor *mon, BusState *bus, int indent)qdev_printf ("bus: %s\n" , bus->name); indent +=2 ; -qdev_printf ("type %s\n" , bus->info->name); +qdev_printf ("type %s, nr %d\n" , bus->info->name, bus->busnr); LIST_FOREACH(dev, &bus->children, sibling) {qdev_print (mon, dev, indent); }
@@ -380,3 +408,14 @@ void do_info_qtree(Monitor *mon)if (main_system_bus)qbus_print (mon, main_system_bus,0 ); } + +void do_info_qbus (Monitor *mon) +{ +BusState *bus; + + TAILQ_FOREACH(bus, &buslist, next) { +monitor_printf (mon,"%s: type %s, nr %d, parent %s\n" , + bus->name, bus->info->name, bus->busnr, + bus->parent ? bus->parent->info->name :"<none>" ); + } +}
hw/qdev.h +5 -0
@@ -32,14 +32,17 @@ struct BusInfo {const char *name;size_t size;bus_dev_print print; +int next_busnr; };struct BusState {DeviceState *parent;BusInfo *info; +int busnr;const char *name; LIST_HEAD(, DeviceState) children;LIST_ENTRY (BusState) sibling; +TAILQ_ENTRY (BusState) next; };/*** Board API. This should go away once we have a machine config file. ***/
@@ -117,11 +120,13 @@ void *qdev_get_prop_ptr(DeviceState *dev, const char *name);/*** BUS API. ***/ BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name); +BusState *qbus_find (const char *type,const char *name,int busnr);#define FROM_QBUS (type, dev) DO_UPCAST(type, qbus, dev)/*** monitor commands ***/ void do_info_qtree (Monitor *mon); +void do_info_qbus (Monitor *mon);#endif
monitor.c +2 -0
@@ -1741,6 +1741,8 @@ static const mon_cmd_t info_cmds[] = { "", "show balloon information" }, {"qtree" ,"" , do_info_qtree, "", "show device tree" }, + { "qbus", "", do_info_qbus, + "", "show qdev bus list" }, { NULL, NULL, }, };
Signature · 1 line
1.6.2.5
PATCH 1/20 qdev: update pci device registration.
In reply to Gerd HoffmannMakes 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 | 25 +++++++++++++++++++------ hw/lsi53c895a.c | 8 +++++++- hw/ne2000.c | 8 +++++++- hw/pci.c | 24 ++++++++++-------------- hw/pci.h | 10 +++++++++- hw/pcnet.c | 8 +++++++- hw/rtl8139.c | 8 +++++++- hw/versatile_pci.c | 9 +++++++-- hw/virtio-pci.c | 31 +++++++++++++++++++++++-------- 10 files changed, 103 insertions(+), 36 deletions(-)
hw/e1000.c +7 -1
@@ -1125,9 +1125,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); }device_init (e1000_register_devices)
hw/eepro100.c +19 -6
@@ -1792,14 +1792,27 @@ 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, + },{ +/* end of list */ + } +}; +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_many (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); }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); }device_init (ne2000_register_devices)
hw/pci.c +10 -14
@@ -938,11 +938,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;
@@ -953,25 +948,26 @@ 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) { -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 ; -qdev_register (&info->qdev); } +void pci_qdev_register_many (PCIDeviceInfo *info) +{ +while (info->qdev.name) { +pci_qdev_register (info); + info++; + } +} +PCIDevice *pci_create_simple (PCIBus *bus,int devfn,const char *name) {DeviceState *dev;
hw/pci.h +9 -1
@@ -217,7 +217,15 @@ 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); +void pci_qdev_register_many (PCIDeviceInfo *info);PCIDevice *pci_create (const char *name,const char *devaddr);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);#if defined (TARGET_SPARC ) && !defined(TARGET_SPARC64 )sysbus_register_dev ("lance" ,sizeof (SysBusPCNetState), lance_init);#endif
hw/rtl8139.c +7 -1
@@ -3499,9 +3499,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); }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); }device_init (versatile_pci_register_devices)
hw/virtio-pci.c +23 -8
@@ -336,16 +336,31 @@ 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, + },{ +/* end of list */ + } +}; +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_many (virtio_info); }device_init (virtio_pci_register_devices)
Signature · 1 line
1.6.2.5
PATCH 2/20 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.5
PATCH 5/20 qdev/core: add monitor command to list all drivers
In reply to Gerd Hoffmann--- hw/qdev.c | 10 ++++++++++ hw/qdev.h | 1 + monitor.c | 2 ++ 3 files changed, 13 insertions(+), 0 deletions(-)
hw/qdev.c +10 -0
@@ -419,3 +419,13 @@ void do_info_qbus(Monitor *mon) bus->parent ? bus->parent->info->name : "<none>"); } } + +void do_info_qdrv (Monitor *mon) +{ +DeviceInfo *info; + +for (info = device_info_list; info !=NULL ; info = info->next) { +monitor_printf (mon,"name \"%s\", bus %s\n" , + info->name, info->bus_info->name); + } +}
hw/qdev.h +1 -0
@@ -128,5 +128,6 @@ BusState *qbus_find(const char *type, const char *name, int busnr);void do_info_qtree (Monitor *mon);void do_info_qbus (Monitor *mon); +void do_info_qdrv (Monitor *mon);#endif
monitor.c +2 -0
@@ -1743,6 +1743,8 @@ static const mon_cmd_t info_cmds[] = { "", "show device tree" }, {"qbus" ,"" , do_info_qbus, "", "show qdev bus list" }, + { "qdrv", "", do_info_qdrv, + "", "show qdev driver list" }, { NULL, NULL, }, };
Signature · 1 line
1.6.2.5
PATCH 6/20 qdev/pci: misc fixes.
In reply to Gerd Hoffmann * use core busnr.
* fix secondary bus setup.
* use base->name instead of "FIXME" for device name. Yes, the device name is redundant. Only for drivers converted to qdev already though. Once all drivers are converted we can and should kill it.
--- hw/pci.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
hw/pci.c +4 -4
@@ -115,7 +115,6 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name, qemu_irq *pic, int devfn_min, int nirq) { PCIBus *bus; -static int nbus =0 ; bus =FROM_QBUS (PCIBus,qbus_create (&pci_bus_info, parent, name)); bus->set_irq = set_irq;
@@ -126,7 +125,7 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name, 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); +register_savevm ("PCIBUS" , bus->qbus.busnr,1 , pcibus_save, pcibus_load, bus);qemu_register_reset (pci_bus_reset,0 , bus);return bus; }
@@ -134,7 +133,8 @@ PCIBus *pci_register_bus(DeviceState *parent, const char *name,static PCIBus *pci_register_secondary_bus (PCIDevice *dev,pci_map_irq_fn map_irq) {PCIBus *bus; - bus =qemu_mallocz (sizeof (PCIBus)); + + bus =FROM_QBUS (PCIBus,qbus_create (&pci_bus_info, &dev->qdev,NULL )); bus->map_irq = map_irq; bus->parent_dev = dev; bus->next = dev->bus->next;
@@ -954,7 +954,7 @@ 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, + pci_dev =do_pci_register_device (pci_dev, bus, base->name, devfn, info->config_read, info->config_write);assert (pci_dev); info->init (pci_dev);
Signature · 1 line
1.6.2.5
PATCH 9/20 qdev: convert piix acpi.
In reply to Gerd HoffmannHook up pci device and smbus into qdev.
TODO: smbus creation is still hardcoded.
--- 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); +} +device_init (acpi_register); +#if defined(TARGET_I386 )void qemu_system_powerdown (void ) {
Signature · 1 line
1.6.2.5
PATCH 7/20 qdev/pci: 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 | 95 +++++++++++++++++++++++++++++++++++++++++--------------- 2 files changed, 72 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 +69 -26
157 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 8/20 qdev: convert piix-ide.
In reply to Gerd HoffmannHook up pci device into qdev.
First step only: no ide bus yet.
--- hw/ide.c | 92 +++++++++++++++++++++++++++++++++++++++++--------------------- 1 files changed, 61 insertions(+), 31 deletions(-)
hw/ide.c +61 -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,69 @@ 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, + },{ +/* end of list */ + } +}; + +static void piix_ide_register (void ) +{ +pci_qdev_register_many (piix_ide_info); } +device_init (piix_ide_register);#if defined(TARGET_PPC )/***********************************************************/
Signature · 1 line
1.6.2.5
PATCH 11/20 qdev: convert es1370.
In reply to Gerd Hoffmann--- hw/es1370.c | 41 ++++++++++++++++++++++------------------- 1 files changed, 22 insertions(+), 19 deletions(-)
hw/es1370.c +22 -19
@@ -1005,27 +1005,12 @@ static void es1370_on_reset (void *opaque)es1370_reset (s); } -int es1370_init (PCIBus *bus) +static void es1370_initfn (PCIDevice *dev) { -PCIES1370State *d; -ES1370State *s; -uint8_t *c; - -if (!bus) { -dolog ("No PCI bus\n" ); -return -1 ; - } - - d = (PCIES1370State *)pci_register_device (bus,"ES1370" , -sizeof (PCIES1370State), --1 ,NULL ,NULL ); - -if (!d) { -AUD_log (NULL ,"Failed to register PCI device for ES1370\n" ); -return -1 ; - } +PCIES1370State *d =DO_UPCAST (PCIES1370State, dev, dev); +ES1370State *s = &d->es1370; +uint8_t *c = d->dev.config; - c = d->dev.config;pci_config_set_vendor_id (c,PCI_VENDOR_ID_ENSONIQ );pci_config_set_device_id (c,PCI_DEVICE_ID_ENSONIQ_ES1370 ); c[0x07 ] =2 <<1 ;
@@ -1059,5 +1044,23 @@ int es1370_init (PCIBus *bus)AUD_register_card ("es1370" , &s->card);es1370_reset (s); +} + +int es1370_init (PCIBus *bus) +{ +pci_create_simple (bus,-1 ,"ES1370" );return 0 ; } + +static PCIDeviceInfo es1370_info = { + .qdev.name ="ES1370" , + .qdev.size =sizeof (PCIES1370State), + .init = es1370_initfn, +}; + +static void es1370_register (void ) +{ +pci_qdev_register (&es1370_info); +} +device_init (es1370_register); +
Signature · 1 line
1.6.2.5
PATCH 17/20 qdev: convert ohci.
In reply to Gerd HoffmannHook pci device into qdev.
TODO: convert non-pci ohci adapters.
--- hw/usb-ohci.c | 42 ++++++++++++++++++++++++++++-------------- 1 files changed, 28 insertions(+), 14 deletions(-)
hw/usb-ohci.c +28 -14
@@ -1661,7 +1661,8 @@ static CPUWriteMemoryFunc *ohci_writefn[3]={ ohci_mem_write }; -static void usb_ohci_init (OHCIState *ohci,int num_ports,int devfn, +static void usb_ohci_init (OHCIState *ohci,DeviceState *dev, +int num_ports,int devfn,qemu_irq irq,enum ohci_type type,const char *name,uint32_t localmem_base) {
@@ -1690,7 +1691,7 @@ static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn, ohci->irq = irq; ohci->type = type; - ohci->bus =usb_bus_new (NULL /* FIXME */ ); + ohci->bus =usb_bus_new (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);
@@ -1713,16 +1714,9 @@ static void ohci_mapfunc(PCIDevice *pci_dev, int i,cpu_register_physical_memory (addr, size, ohci->state.mem); } -void usb_ohci_init_pci (struct PCIBus *bus,int num_ports,int devfn) +static void usb_ohci_initfn_pci (struct PCIDevice *dev) { -OHCIPCIState *ohci; - - ohci = (OHCIPCIState *)pci_register_device (bus,"OHCI USB" ,sizeof (*ohci), - devfn,NULL ,NULL ); -if (ohci ==NULL ) { -fprintf (stderr,"usb-ohci: Failed to register PCI device\n" ); -return ; - } +OHCIPCIState *ohci =DO_UPCAST (OHCIPCIState, pci_dev, dev);pci_config_set_vendor_id (ohci->pci_dev.config,PCI_VENDOR_ID_APPLE ); pci_config_set_device_id(ohci->pci_dev.config,
@@ -1730,8 +1724,17 @@ void usb_ohci_init_pci(struct PCIBus *bus, int num_ports, int devfn) ohci->pci_dev.config[0x09 ] =0x10 ;/* OHCI */ pci_config_set_class (ohci->pci_dev.config,PCI_CLASS_SERIAL_USB ); ohci->pci_dev.config[0x3d ] =0x01 ;/* interrupt pin 1 */ +} -usb_ohci_init (&ohci->state, num_ports, devfn, ohci->pci_dev.irq[0 ], +void usb_ohci_init_pci (struct PCIBus *bus,int num_ports,int devfn) +{ +PCIDevice *dev; +OHCIPCIState *ohci; + + dev =pci_create_simple (bus, devfn,"OHCI USB" ); + ohci =DO_UPCAST (OHCIPCIState, pci_dev, dev); + +usb_ohci_init (&ohci->state, &dev->qdev, num_ports, devfn, ohci->pci_dev.irq[0 ],OHCI_TYPE_PCI , ohci->pci_dev.name,0 ); pci_register_bar((struct PCIDevice *)ohci, 0, 256,
@@ -1743,7 +1746,7 @@ void usb_ohci_init_pxa(target_phys_addr_t base, int num_ports, int devfn, {OHCIState *ohci = (OHCIState *)qemu_mallocz (sizeof (OHCIState)); -usb_ohci_init (ohci, num_ports, devfn, irq, +usb_ohci_init (ohci,NULL /* FIXME */ , num_ports, devfn, irq,OHCI_TYPE_PXA ,"OHCI USB" ,0 );cpu_register_physical_memory (base,0x1000 , ohci->mem);
@@ -1754,9 +1757,20 @@ void usb_ohci_init_sm501(uint32_t mmio_base, uint32_t localmem_base, {OHCIState *ohci = (OHCIState *)qemu_mallocz (sizeof (OHCIState)); -usb_ohci_init (ohci, num_ports, devfn, irq, +usb_ohci_init (ohci,NULL /* FIXME */ , num_ports, devfn, irq,OHCI_TYPE_SM501 ,"OHCI USB" , localmem_base);cpu_register_physical_memory (mmio_base,0x1000 , ohci->mem); } +static PCIDeviceInfo ohci_info = { + .qdev.name ="OHCI USB" , + .qdev.size =sizeof (OHCIPCIState), + .init = usb_ohci_initfn_pci, +}; + +static void ohci_register (void ) +{ +pci_qdev_register (&ohci_info); +} +device_init (ohci_register);
Signature · 1 line
1.6.2.5
PATCH 12/20 qdev: convert ac97.
In reply to Gerd Hoffmann--- hw/ac97.c | 42 ++++++++++++++++++++++-------------------- 1 files changed, 22 insertions(+), 20 deletions(-)
hw/ac97.c +22 -20
@@ -1308,29 +1308,13 @@ static void ac97_on_reset (void *opaque)mixer_reset (s); } -int ac97_init (PCIBus *bus) +static void ac97_initfn (PCIDevice *dev) { -PCIAC97LinkState *d; -AC97LinkState *s; -uint8_t *c; - -if (!bus) { -AUD_log ("ac97" ,"No PCI bus\n" ); -return -1 ; - } - - d = (PCIAC97LinkState *)pci_register_device (bus,"AC97" , -sizeof (PCIAC97LinkState), --1 ,NULL ,NULL ); - -if (!d) { -AUD_log ("ac97" ,"Failed to register PCI device\n" ); -return -1 ; - } +PCIAC97LinkState *d =DO_UPCAST (PCIAC97LinkState, dev, dev); +AC97LinkState *s = &d->ac97; +uint8_t *c = d->dev.config; - s = &d->ac97; s->pci_dev = &d->dev; - c = d->dev.config;pci_config_set_vendor_id (c,PCI_VENDOR_ID_INTEL );/* ro */ pci_config_set_device_id (c,PCI_DEVICE_ID_INTEL_82801AA_5 );/* ro */
@@ -1372,5 +1356,23 @@ int ac97_init (PCIBus *bus)qemu_register_reset (ac97_on_reset,0 , s);AUD_register_card ("ac97" , &s->card);ac97_on_reset (s); +} + +int ac97_init (PCIBus *bus) +{ +pci_create_simple (bus,-1 ,"AC97" );return 0 ; } + +static PCIDeviceInfo ac97_info = { + .qdev.name ="AC97" , + .qdev.size =sizeof (PCIAC97LinkState), + .init = ac97_initfn, +}; + +static void ac97_register (void ) +{ +pci_qdev_register (&ac97_info); +} +device_init (ac97_register); +
Signature · 1 line
1.6.2.5
PATCH 10/20 qdev: convert all vga
In reply to Gerd Hoffmann--- hw/cirrus_vga.c | 85 ++++++++++++++++++++++++++++++------------------------ hw/vga.c | 66 ++++++++++++++++++++++++++---------------- hw/vmware_vga.c | 26 +++++++++++++---- 3 files changed, 108 insertions(+), 69 deletions(-)
hw/cirrus_vga.c +47 -38
@@ -3301,46 +3301,55 @@ static void pci_cirrus_write_config(PCIDevice *d,cirrus_update_memory_access (s); } +static void pci_cirrus_vga_initfn (PCIDevice *dev) +{ +PCICirrusVGAState *d =DO_UPCAST (PCICirrusVGAState, dev, dev); +CirrusVGAState *s = &d->cirrus_vga; +uint8_t *pci_conf = d->dev.config; +int device_id =CIRRUS_ID_CLGD5446 ; + +/* setup VGA */ +vga_common_init (&s->vga,VGA_RAM_SIZE ); +cirrus_init_common (s, device_id,1 ); + s->vga.pci_dev = (PCIDevice *)d; + s->vga.ds =graphic_console_init (s->vga.update, s->vga.invalidate, + s->vga.screen_dump, s->vga.text_update, + &s->vga); + +/* setup PCI */ +pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_CIRRUS ); +pci_config_set_device_id (pci_conf, device_id); + pci_conf[0x04 ] =PCI_COMMAND_IOACCESS |PCI_COMMAND_MEMACCESS ; +pci_config_set_class (pci_conf,PCI_CLASS_DISPLAY_VGA ); + pci_conf[PCI_HEADER_TYPE ] =PCI_HEADER_TYPE_NORMAL ; + +/* setup memory space */ +/* memory #0 LFB */ +/* memory #1 memory-mapped I/O */ +/* XXX: s->vga.vram_size must be a power of two */ +pci_register_bar ((PCIDevice *)d,0 ,0x2000000 , +PCI_ADDRESS_SPACE_MEM_PREFETCH , cirrus_pci_lfb_map); +if (device_id ==CIRRUS_ID_CLGD5446 ) { +pci_register_bar ((PCIDevice *)d,1 ,CIRRUS_PNPMMIO_SIZE , +PCI_ADDRESS_SPACE_MEM , cirrus_pci_mmio_map); + } +/* XXX: ROM BIOS */ +} +void pci_cirrus_vga_init (PCIBus *bus) { -PCICirrusVGAState *d; -uint8_t *pci_conf; -CirrusVGAState *s; -int device_id; - - device_id =CIRRUS_ID_CLGD5446 ; - -/* setup PCI configuration registers */ - d = (PCICirrusVGAState *)pci_register_device (bus,"Cirrus VGA" , -sizeof (PCICirrusVGAState), --1 ,NULL , pci_cirrus_write_config); - pci_conf = d->dev.config; -pci_config_set_vendor_id (pci_conf,PCI_VENDOR_ID_CIRRUS ); -pci_config_set_device_id (pci_conf, device_id); - pci_conf[0x04 ] =PCI_COMMAND_IOACCESS |PCI_COMMAND_MEMACCESS ; -pci_config_set_class (pci_conf,PCI_CLASS_DISPLAY_VGA ); - pci_conf[PCI_HEADER_TYPE ] =PCI_HEADER_TYPE_NORMAL ; - -/* setup VGA */ - s = &d->cirrus_vga; -vga_common_init (&s->vga,VGA_RAM_SIZE ); -cirrus_init_common (s, device_id,1 ); - - s->vga.ds =graphic_console_init (s->vga.update, s->vga.invalidate, - s->vga.screen_dump, s->vga.text_update, - &s->vga); +pci_create_simple (bus,-1 ,"Cirrus VGA" ); +} - s->vga.pci_dev = (PCIDevice *)d; +static PCIDeviceInfo cirrus_vga_info = { + .qdev.name ="Cirrus VGA" , + .qdev.size =sizeof (PCICirrusVGAState), + .init = pci_cirrus_vga_initfn, + .config_write = pci_cirrus_write_config, +}; -/* setup memory space */ -/* memory #0 LFB */ -/* memory #1 memory-mapped I/O */ -/* XXX: s->vga.vram_size must be a power of two */ -pci_register_bar ((PCIDevice *)d,0 ,0x2000000 , -PCI_ADDRESS_SPACE_MEM_PREFETCH , cirrus_pci_lfb_map); -if (device_id ==CIRRUS_ID_CLGD5446 ) { -pci_register_bar ((PCIDevice *)d,1 ,CIRRUS_PNPMMIO_SIZE , -PCI_ADDRESS_SPACE_MEM , cirrus_pci_mmio_map); - } -/* XXX: ROM BIOS */ +static void cirrus_vga_register (void ) +{ +pci_qdev_register (&cirrus_vga_info); } +device_init (cirrus_vga_register);
hw/vga.c +41 -25
90 lines not on this page · raw message
hw/vmware_vga.c +20 -6
@@ -1210,14 +1210,11 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num, iomemtype); } -void pci_vmsvga_init (PCIBus *bus) +static void pci_vmsvga_initfn (PCIDevice *dev) { -struct pci_vmsvga_state_s *s; +struct pci_vmsvga_state_s *s = + DO_UPCAST(struct pci_vmsvga_state_s, card, dev); -/* Setup PCI configuration */ - s = (struct pci_vmsvga_state_s *) -pci_register_device (bus,"QEMUware SVGA" , -sizeof (struct pci_vmsvga_state_s ),-1 ,NULL ,NULL );pci_config_set_vendor_id (s->card.config,PCI_VENDOR_ID_VMWARE );pci_config_set_device_id (s->card.config,SVGA_PCI_DEVICE_ID ); s->card.config[PCI_COMMAND ] =0x07 ;/* I/O + Memory */
@@ -1240,3 +1237,20 @@ void pci_vmsvga_init(PCIBus *bus)register_savevm ("vmware_vga" ,0 ,0 , pci_vmsvga_save, pci_vmsvga_load, s); } + +void pci_vmsvga_init (PCIBus *bus) +{ +pci_create_simple (bus,-1 ,"QEMUware SVGA" ); +} + +static PCIDeviceInfo vmsvga_info = { + .qdev.name ="QEMUware SVGA" , + .qdev.size =sizeof (struct pci_vmsvga_state_s ), + .init = pci_vmsvga_initfn, +}; + +static void vmsvga_register (void ) +{ +pci_qdev_register (&vmsvga_info); +} +device_init (vmsvga_register);
Signature · 1 line
1.6.2.5
PATCH 13/20 qdev: convert uhci.
In reply to Gerd HoffmannHookup pci device into qdev.
No usb bus yet, see following patches.
--- hw/usb-uhci.c | 74 +++++++++++++++++++++++++++++++------------------------- 1 files changed, 41 insertions(+), 33 deletions(-)
hw/usb-uhci.c +41 -33
@@ -1070,18 +1070,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 );
@@ -1105,37 +1098,52 @@ 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, + },{ +/* end of list */ } - s->frame_timer =qemu_new_timer (vm_clock, uhci_frame_timer, s); +}; -qemu_register_reset (uhci_reset,0 , s); -uhci_reset (s); +static void uhci_register (void ) +{ +pci_qdev_register_many (uhci_info); +} +device_init (uhci_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.5
PATCH 16/20 qdev/usb: print usb dev info
In reply to Gerd Hoffmann--- hw/usb-bus.c | 26 ++++++++++++++++++++++++++ hw/usb.h | 1 + vl.c | 17 +---------------- 3 files changed, 28 insertions(+), 16 deletions(-)
hw/usb-bus.c +26 -0
@@ -1,10 +1,14 @@#include "hw.h" #include "usb.h" #include "qdev.h" +#include "monitor.h" + +static void usb_bus_dev_print (Monitor *mon,DeviceState *qdev,int indent);static struct BusInfo usb_bus_info = { .name ="USB" , .size =sizeof (USBBus), + .print = usb_bus_dev_print, };USBBus *usb_bus_new (DeviceState *host)
@@ -137,3 +141,25 @@ int usb_device_delete_addr(int busnr, int addr) bus->nfree++;return 0 ; } + +const char *usb_speed (unsigned int speed) +{ +static const char *txt[] = { + [USB_SPEED_LOW ] ="1.5" , + [USB_SPEED_FULL ] ="12" , + [USB_SPEED_HIGH ] ="480" , + }; +if (speed >=ARRAY_SIZE (txt)) +return "?" ; +return txt[speed]; +} + +static void usb_bus_dev_print (Monitor *mon,DeviceState *qdev,int indent) +{ +USBDevice *dev =DO_UPCAST (USBDevice, qdev, qdev); +USBBus *bus =usb_bus_from_device (dev); + +monitor_printf (mon,"%*saddr %d.%d, speed %s, name %s\n" , indent,"" , + bus->qbus.busnr, dev->addr, +usb_speed (dev->speed), dev->devname); +}
hw/usb.h +1 -0
@@ -309,6 +309,7 @@ void usb_register_port(USBBus *bus, USBPort *port, void *opaque, int index, usb_attachfn attach);int usb_device_attach (USBDevice *dev);int usb_device_delete_addr (int busnr,int addr); +const char *usb_speed (unsigned int speed);static inline USBBus *usb_bus_from_device (USBDevice *d) {
vl.c +1 -16
@@ -2746,7 +2746,6 @@ void usb_info(Monitor *mon)USBBus *bus;USBDevice *dev;USBPort *port; -const char *speed_str;int busnr;if (!usb_enabled) {
@@ -2762,22 +2761,8 @@ void usb_info(Monitor *mon) dev = port->dev;if (!dev)continue ; -switch (dev->speed) { -case USB_SPEED_LOW : - speed_str ="1.5" ; -break ; -case USB_SPEED_FULL : - speed_str ="12" ; -break ; -case USB_SPEED_HIGH : - speed_str ="480" ; -break ; -default : - speed_str ="?" ; -break ; - }monitor_printf (mon," Device %d.%d, Speed %s Mb/s, Product %s\n" , - busnr, dev->addr, speed_str, dev->devname); + busnr, dev->addr,usb_speed (dev->speed), dev->devname); } } }
Signature · 1 line
1.6.2.5
PATCH 15/20 qdev/usb: make qemu aware of usb busses.
In reply to Gerd HoffmannMove usb code from vl.c to usb-bus.c and make it use the new data structures added by qdev conversion. qemu usb core should be able to handle multiple USB busses just fine now (untested though).
Kill some usb_*_init() legacy functions, use usb_create_simple() instead.
Kill some FIXMEs added by the first qdev/usb patch.
--- hw/bt-hid.c | 3 +- hw/usb-bus.c | 98 +++++++++++++++++++++++++++++---- hw/usb-hid.c | 15 ----- hw/usb-hub.c | 8 +-- hw/usb-musb.c | 4 +- hw/usb-ohci.c | 4 +- hw/usb-uhci.c | 4 +- hw/usb-wacom.c | 5 -- hw/usb.h | 31 ++++++----- usb-linux.c | 10 ++-- vl.c | 165 +++++++++++++++++++++----------------------------------- 11 files changed, 181 insertions(+), 166 deletions(-)
hw/bt-hid.c +2 -1
@@ -567,5 +567,6 @@ static struct bt_device_s *bt_hid_init(struct bt_scatternet_s *net,struct bt_device_s *bt_keyboard_init (struct bt_scatternet_s *net) { -return bt_hid_init (net,usb_keyboard_init (), class_keyboard); +USBDevice *dev =usb_create_simple (NULL /* FIXME */ ,"QEMU USB Keyboard" ); +return bt_hid_init (net, dev, class_keyboard); }
hw/usb-bus.c +86 -12
121 lines not on this page · raw message
hw/usb-hid.c +0 -15
@@ -870,21 +870,6 @@ static void usb_keyboard_initfn(USBDevice *dev)usb_hid_initfn (dev,USB_KEYBOARD ); } -USBDevice *usb_tablet_init (void ) -{ -return usb_create_simple (NULL /* FIXME */ ,"QEMU USB Tablet" ); -} - -USBDevice *usb_mouse_init (void ) -{ -return usb_create_simple (NULL /* FIXME */ ,"QEMU USB Mouse" ); -} - -USBDevice *usb_keyboard_init (void ) -{ -return usb_create_simple (NULL /* FIXME */ ,"QEMU USB Keyboard" ); -} -void usb_hid_datain_cb (USBDevice *dev,void *opaque,void (*datain)(void *)) {USBHIDState *s = (USBHIDState *)dev;
hw/usb-hub.c +2 -6
@@ -531,17 +531,13 @@ static void usb_hub_initfn(USBDevice *dev) s->nb_ports =MAX_PORTS ;/* FIXME: make configurable */ for (i =0 ; i < s->nb_ports; i++) { port = &s->ports[i]; -qemu_register_usb_port (&port->port, s, i, usb_hub_attach); +usb_register_port (usb_bus_from_device (dev), + &port->port, s, i, usb_hub_attach); port->wPortStatus =PORT_STAT_POWER ; port->wPortChange =0 ; } } -USBDevice *usb_hub_init (int nb_ports) -{ -return usb_create_simple (NULL /* FIXME */ ,"QEMU USB Hub" ); -} -static struct USBDeviceInfo hub_info = { .qdev.name ="QEMU USB Hub" , .qdev.size =sizeof (USBHubState),
hw/usb-musb.c +3 -1
@@ -282,6 +282,7 @@ typedef struct {struct MUSBState {qemu_irq *irqs; +USBBus *bus;USBPort port;int idx;
@@ -331,7 +332,8 @@ struct MUSBState { s->ep[i].epnum = i; } -qemu_register_usb_port (&s->port, s,0 , musb_attach); + s->bus =usb_bus_new (NULL /* FIXME */ ); +usb_register_port (s->bus, &s->port, s,0 , musb_attach);return s; }
hw/usb-ohci.c +3 -1
@@ -66,6 +66,7 @@ enum ohci_type { }; typedef struct { + USBBus *bus; qemu_irq irq; enum ohci_type type; int mem;
@@ -1689,9 +1690,10 @@ static void usb_ohci_init(OHCIState *ohci, int num_ports, int devfn, ohci->irq = irq; ohci->type = type; + ohci->bus =usb_bus_new (NULL /* FIXME */ ); ohci->num_ports = num_ports;for (i =0 ; i < num_ports; i++) { -qemu_register_usb_port (&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 +2 -2
@@ -1083,8 +1083,9 @@ static void 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);for (i =0 ; i <NB_PORTS ; i++) { -qemu_register_usb_port (&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);
@@ -1096,7 +1097,6 @@ 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 +0 -5
@@ -398,11 +398,6 @@ static void usb_wacom_initfn(USBDevice *dev) s->dev.speed =USB_SPEED_FULL ; } -USBDevice *usb_wacom_init (void ) -{ -return usb_create_simple (NULL /* FIXME */ ,"QEMU PenPartner Tablet" ); -} -static struct USBDeviceInfo wacom_info = { .qdev.name ="QEMU PenPartner Tablet" , .qdev.size =sizeof (USBWacomState),
hw/usb.h +16 -15
@@ -24,6 +24,7 @@#include "block.h" #include "qdev.h" +#include "sys-queue.h" #define USB_TOKEN_SETUP 0x2d#define USB_TOKEN_IN 0x69/* device -> host */
@@ -191,7 +192,7 @@ struct USBPort {usb_attachfn attach;void *opaque;int index;/* internal port index, may be used with the opaque */ -struct USBPort *next;/* Used internally by qemu. */ +TAILQ_ENTRY (USBPort) next; };typedef void USBCallback (USBPacket * packet,void *opaque);
@@ -236,25 +237,17 @@ static inline void usb_cancel_packet(USBPacket * p) p->cancel_cb (p, p->cancel_opaque); } -int usb_device_add_dev (USBDevice *dev); -int usb_device_del_addr (int bus_num,int addr);void usb_attach (USBPort *port,USBDevice *dev);int usb_generic_handle_packet (USBDevice *s,USBPacket *p);int set_usb_string (uint8_t *buf,const char *str);void usb_send_msg (USBDevice *dev,int msg); -/* usb hub */ -USBDevice *usb_hub_init (int nb_ports); -/* usb-linux.c */ USBDevice *usb_host_device_open (const char *devname);int usb_host_device_close (const char *devname);void usb_host_info (Monitor *mon);/* usb-hid.c */ -USBDevice *usb_mouse_init (void ); -USBDevice *usb_tablet_init (void ); -USBDevice *usb_keyboard_init (void );void usb_hid_datain_cb (USBDevice *dev,void *opaque,void (*datain)(void *));/* usb-msd.c */
@@ -267,17 +260,11 @@ USBDevice *usb_net_init(NICInfo *nd);/* usb-bt.c */ USBDevice *usb_bt_init (HCIInfo *hci); -/* usb-wacom.c */ -USBDevice *usb_wacom_init (void ); -/* usb-serial.c */ USBDevice *usb_serial_init (const char *filename);/* usb ports of the VM */ -void qemu_register_usb_port (USBPort *port,void *opaque,int index, -usb_attachfn attach); -#define VM_USB_HUB_SIZE 8/* usb-musb.c */
@@ -307,9 +294,23 @@ void musb_set_size(MUSBState *s, int epnum, int size, int is_tx);struct USBBus {BusState qbus; +int nfree; +int nused; + TAILQ_HEAD(, USBPort) free; + TAILQ_HEAD(, USBPort) used; };USBBus *usb_bus_new (DeviceState *host); +USBBus *usb_bus_find (int busnr);void usb_qdev_register (USBDeviceInfo *info);void usb_qdev_register_many (USBDeviceInfo *info);USBDevice *usb_create_simple (USBBus *bus,const char *name); +void usb_register_port (USBBus *bus,USBPort *port,void *opaque,int index, +usb_attachfn attach); +int usb_device_attach (USBDevice *dev); +int usb_device_delete_addr (int busnr,int addr); + +static inline USBBus *usb_bus_from_device (USBDevice *d) +{ +return DO_UPCAST (USBBus, qbus, d->qdev.parent_bus); +}
usb-linux.c +5 -5
@@ -252,7 +252,7 @@ static void async_complete(void *opaque)if (errno ==ENODEV && !s->closing) {printf ("husb: device %d.%d disconnected\n" , s->bus_num, s->addr); -usb_device_del_addr (0 , s->dev.addr); +usb_device_delete_addr (s->bus_num, s->dev.addr);return ; }
@@ -1038,16 +1038,16 @@ int usb_host_device_close(const char *devname)if (usb_host_find_device (&bus_num, &addr, product_name,sizeof (product_name), devname) <0 )return -1 ; - + s =hostdev_find (bus_num, addr);if (s) { -usb_device_del_addr (0 , s->dev.addr); +usb_device_delete_addr (s->bus_num, s->dev.addr);return 0 ; }return -1 ; } - +static int get_tag_value (char *buf,int buf_size,const char *str,const char *tag,const char *stopchars)
@@ -1386,7 +1386,7 @@ static int usb_host_auto_scan(void *opaque, int bus_num, int addr, dev =usb_host_device_open_addr (bus_num, addr, product_name);if (dev) -usb_device_add_dev (dev); +usb_device_attach (dev); }return 0 ;
vl.c +62 -103
229 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 14/20 qdev/usb: add usb bus support to qdev, convert drivers.
In reply to Gerd Hoffmann * Add USBBus.
* Add USBDeviceInfo, move device callbacks here.
* Add usb-qdev helper functions.
* Switch drivers to qdev.
TODO:
* make the rest of qemu aware of usb busses and kill the FIXMEs added by this patch.
--- Makefile | 2 +- hw/bt-hid.c | 18 +++++----- hw/usb-bt.c | 37 ++++++++++++++----- hw/usb-bus.c | 65 ++++++++++++++++++++++++++++++++++ hw/usb-hid.c | 105 ++++++++++++++++++++++++++++++++----------------------- 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 | 62 ++++++++++++++++++++------------ usb-linux.c | 52 +++++++++++++++++++-------- vl.c | 4 +- 17 files changed, 394 insertions(+), 193 deletions(-) create mode 100644 hw/usb-bus.c
Makefile +1 -1
@@ -103,7 +103,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); } +device_init (usb_bt_register_devices)
hw/usb-bus.c new file +65 -0
65 lines not on this page · raw message
hw/usb-hid.c +61 -44
129 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 */
@@ -660,7 +661,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);
@@ -1095,6 +1096,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); } +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 +39 -23
102 lines not on this page · raw message
usb-linux.c +36 -16
97 lines not on this page · raw message
vl.c +2 -2
@@ -2667,7 +2667,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)
@@ -2753,7 +2753,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.5
PATCH 18/20 qdev/scsi: add scsi bus support to qdev, convert drivers.
In reply to Gerd Hoffmann * Add SCSIBus
* Add SCSIDeviceInfo, move device callbacks here.
* add qdev/scsi helper functions.
* convert drivers.
TODO:
* design a better way to link (guest) scsi devs to (host) bdrvs.
* figure whenever we can move bits from lsi / esp scsi host drivers to scsi-bus.c (attach function?).
--- Makefile | 2 +- hw/esp.c | 28 ++++++++++++---------- hw/lsi53c895a.c | 31 ++++++++++++++----------- hw/qdev.c | 18 --------------- hw/qdev.h | 4 --- hw/scsi-bus.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ hw/scsi-disk.c | 64 ++++++++++++++++++++++++++++++---------------------- hw/scsi-disk.h | 48 +++++++++++++++++++++++++++++++++------ hw/scsi-generic.c | 62 ++++++++++++++++++++++++++++++++------------------- hw/usb-msd.c | 24 ++++++++++--------- 10 files changed, 223 insertions(+), 119 deletions(-) create mode 100644 hw/scsi-bus.c
Makefile +1 -1
@@ -101,7 +101,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 ) {
@@ -634,13 +635,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,
@@ -684,7 +685,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 -18
@@ -288,24 +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); - } -} static TAILQ_HEAD(, BusState) buslist = TAILQ_HEAD_INITIALIZER(buslist);BusState *qbus_create (BusInfo *info,DeviceState *parent,const char *name)
hw/qdev.h +0 -4
@@ -76,8 +76,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;
@@ -97,8 +95,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 +61 -0
61 lines not on this page · raw message
hw/scsi-disk.c +37 -27
158 lines not on this page · raw message
hw/scsi-disk.h +40 -8
73 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.5
PATCH 19/20 debug/test patch: add ohci controller to pc
In reply to Gerd Hoffmann--- hw/pc.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pc.c +1 -0
@@ -1121,6 +1121,7 @@ static void pc_init1(ram_addr_t ram_size,if (pci_enabled && usb_enabled) {usb_uhci_piix3_init (pci_bus, piix3_devfn +2 ); +usb_ohci_init_pci (pci_bus,3 ,-1 ); }if (pci_enabled && acpi_enabled) {
Signature · 1 line
1.6.2.5
PATCH 20/20 debug/test patch: allow specify busnr for -usbdevice
In reply to Gerd Hoffmanni.e. -usbdevice tablet,busnr=1
--- vl.c | 19 +++++++++++++++++-- 1 files changed, 17 insertions(+), 2 deletions(-)
vl.c +17 -2
@@ -2649,16 +2649,31 @@ static struct { } }; -static int usb_device_add (const char *devname,int is_hotplug) +static int usb_device_add (const char *config,int is_hotplug) {const char *p; -USBBus *bus =usb_bus_find (-1 /* any */ ); +char devname[32 ], buf[32 ], *params; +int busnr =-1 ;/* any */ +USBBus *bus;USBDevice *dev =NULL ;int i;if (!usb_enabled)return -1 ; +pstrcpy (devname,sizeof (devname), config); +if ((params =strchr (devname,',' )) !=NULL ) { + *params =0 ; + params++; +if (get_param_value (buf,sizeof (buf),"busnr" , params)) + busnr =atoi (buf); + } + + bus =usb_bus_find (busnr); +if (!bus) +return -1 ; +fprintf (stderr,"%s: busnr=%d, bus=%s\n" , __FUNCTION__, busnr, bus->qbus.name); +/* simple devices which don't need extra care */ for (i =0 ; i <ARRAY_SIZE (usbdevs); i++) {if (strcmp (devname, usbdevs[i].name) !=0 )
Signature · 1 line
1.6.2.5
Quoted 9 lines · Gerd Hoffmann
Hi,
This is a respin of my qdev patches. They are rebased to the latest master. Addressed review comments, partly by changing code, partly by clarifying commit messages.
The first five patches build the groundwork, I'd like to see them merged soon.
Can you split out the first five into a separate series then? We can focus on getting those right, merge them, and then pick up the rest.
I just did a large push (it's apparently been an active week) and I was not brave/eager enough rebase your patches on top of my queue :-)
Regards,
Anthony Liguori
Quoted 6 lines
cheers,
Gerd
Quoted 2 lines · Anthony Liguori
Can you split out the first five into a separate series then? We can focus on getting those right, merge them, and then pick up the rest.
Rebased, sent.
cheers,
Gerd