qdev patches, batch #2
cover qdev patches, batch #2
Hi,
This is the next round of qdev patches for review. These patches depend on "batch #1" and the "rework device properties" patches sent out yesterday.
The patches implement a -device command line switch and add the qdev functionality backing that. For now only pci devices are supported for -device. The patches also do some cleanups along the way. Also converts vga to qdev (completely). Check the individual patch descriptions for more details.
In the works, but not yet posted: convert usb+scsi to qdev, hook up usb to -device, convert more devices.
My complete qdev patch queue (including the patches posted yesterday, this patch series and the upcoming usb/scsi bits) is available here:
http://git.et.redhat.com/?p=qemu-kraxel.git;a=shortlog;h=refs/heads/qdev.v8
cheers,
Gerd
PATCH 1/8 qdev: factor out driver search to qdev_find_info()
--- hw/qdev.c | 22 +++++++++++++++------- 1 files changed, 15 insertions(+), 7 deletions(-)
hw/qdev.c +15 -7
@@ -46,6 +46,20 @@ void qdev_register(DeviceInfo *info) device_info_list = info; } +static DeviceInfo *qdev_find_info (BusInfo *bus_info,const char *name) +{ +DeviceInfo *info; + +for (info = device_info_list; info !=NULL ; info = info->next) { +if (bus_info && info->bus_info != bus_info) +continue ; +if (strcmp (info->name, name) !=0 ) +continue ; +return info; + } +return NULL ; +} +/* Create a new device. This only initializes the device state structure and allows properties to be set. qdev_init should be called to initialize the actual device emulation. */
@@ -61,13 +75,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) bus = main_system_bus; } -for (info = device_info_list; info !=NULL ; info = info->next) { -if (info->bus_info != bus->info) -continue ; -if (strcmp (info->name, name) !=0 ) -continue ; -break ; - } + info =qdev_find_info (bus->info, name);if (!info) {hw_error ("Unknown device '%s' for bus '%s'\n" , name, bus->info->name); }
Signature · 1 line
1.6.2.5
PATCH 2/8 qdev/pci: make pci_create return DeviceState instead of PCIDevice.
In reply to Gerd HoffmannRationale: wanna use it as callback in qdev code.
--- hw/pc.c | 12 ++++++------ hw/pci-hotplug.c | 6 +++--- hw/pci.c | 10 ++++------ hw/pci.h | 2 +- hw/ppc440_bamboo.c | 6 +++--- hw/ppce500_mpc8544ds.c | 6 +++--- 6 files changed, 20 insertions(+), 22 deletions(-)
hw/pc.c +6 -6
@@ -1094,7 +1094,7 @@ static void pc_init1(ram_addr_t ram_size,ram_addr_t below_4g_mem_size, above_4g_mem_size =0 ;int bios_size, isa_bios_size, oprom_area_size;PCIBus *pci_bus; -PCIDevice *pci_dev; +DeviceState *qdev;int piix3_devfn =-1 ;CPUState *env;qemu_irq *cpu_irq;
@@ -1400,17 +1400,17 @@ static void pc_init1(ram_addr_t ram_size,int unit_id =0 ;while ((index =drive_get_index (IF_VIRTIO ,0 , unit_id)) !=-1 ) { - pci_dev =pci_create ("virtio-blk-pci" , - drives_table[index].devaddr); -qdev_init (&pci_dev->qdev); + qdev =pci_create ("virtio-blk-pci" , + drives_table[index].devaddr); +qdev_init (qdev); unit_id++; } }/* Add virtio balloon device */ if (pci_enabled && virtio_balloon) { - pci_dev =pci_create ("virtio-balloon-pci" , virtio_balloon_devaddr); -qdev_init (&pci_dev->qdev); + qdev =pci_create ("virtio-balloon-pci" , virtio_balloon_devaddr); +qdev_init (qdev); }/* Add virtio console devices */
hw/pci-hotplug.c +3 -3
@@ -97,7 +97,7 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon,const char *devaddr, const char *opts) { - PCIDevice *dev; + DeviceState *dev;int type =-1 , drive_idx =-1 ;char buf[128 ];
@@ -139,8 +139,8 @@ static PCIDevice *qemu_pci_hot_add_storage(Monitor *mon, dev =NULL ; }if (dev) -qdev_init (&dev->qdev); -return dev; +qdev_init (dev); +return DO_UPCAST (PCIDevice, qdev, dev); } void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
hw/pci.c +4 -6
@@ -763,7 +763,7 @@ void pci_info(Monitor *mon)pci_for_each_device (0 , pci_info_device); } -PCIDevice *pci_create (const char *name,const char *devaddr) +DeviceState *pci_create (const char *name,const char *devaddr) {PCIBus *bus;int devfn;
@@ -778,7 +778,7 @@ PCIDevice *pci_create(const char *name, const char *devaddr) dev =qdev_create (&bus->qbus, name);qdev_prop_set_uint32 (dev,"devfn" , devfn); -return (PCIDevice *)dev; +return dev; }static const char *const pci_nic_models[] = {
@@ -810,7 +810,6 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model, const char *default_devaddr) {const char *devaddr = nd->devaddr ? nd->devaddr : default_devaddr; -PCIDevice *pci_dev;DeviceState *dev;int i;
@@ -818,12 +817,11 @@ PCIDevice *pci_nic_init(NICInfo *nd, const char *default_model,for (i =0 ; pci_nic_models[i]; i++) {if (strcmp (nd->model, pci_nic_models[i]) ==0 ) { - pci_dev =pci_create (pci_nic_names[i], devaddr); - dev = &pci_dev->qdev; + dev =pci_create (pci_nic_names[i], devaddr); dev->nd = nd;qdev_init (dev); nd->private = dev; -return pci_dev; +return DO_UPCAST (PCIDevice, qdev, dev); } }
hw/pci.h +1 -1
@@ -324,7 +324,7 @@ typedef struct {void pci_qdev_register (PCIDeviceInfo *info);void pci_qdev_register_many (PCIDeviceInfo *info); -PCIDevice *pci_create (const char *name,const char *devaddr); +DeviceState *pci_create (const char *name,const char *devaddr);PCIDevice *pci_create_simple (PCIBus *bus,int devfn,const char *name);/* lsi53c895a.c */
hw/ppc440_bamboo.c +3 -3
@@ -90,7 +90,7 @@ static void bamboo_init(ram_addr_t ram_size, {unsigned int pci_irq_nrs[4 ] = {28 ,27 ,26 ,25 };PCIBus *pcibus; -PCIDevice *pci_dev; +DeviceState *qdev;CPUState *env;uint64_t elf_entry;uint64_t elf_lowaddr;
@@ -111,8 +111,8 @@ static void bamboo_init(ram_addr_t ram_size,/* Add virtio block devices. */ while ((i =drive_get_index (IF_VIRTIO ,0 , unit_id)) !=-1 ) { - pci_dev =pci_create ("virtio-blk-pci" , drives_table[i].devaddr); -qdev_init (&pci_dev->qdev); + qdev =pci_create ("virtio-blk-pci" , drives_table[i].devaddr); +qdev_init (qdev); unit_id++; }
hw/ppce500_mpc8544ds.c +3 -3
@@ -157,7 +157,7 @@ static void mpc8544ds_init(ram_addr_t ram_size, const char *cpu_model) {PCIBus *pci_bus; -PCIDevice *pci_dev; +DeviceState *qdev;CPUState *env;uint64_t elf_entry;uint64_t elf_lowaddr;
@@ -220,8 +220,8 @@ static void mpc8544ds_init(ram_addr_t ram_size,/* Add virtio block devices. */ while ((i =drive_get_index (IF_VIRTIO ,0 , unit_id)) !=-1 ) { - pci_dev =pci_create ("virtio-blk-pci" , drives_table[i].devaddr); -qdev_init (&pci_dev->qdev); + qdev =pci_create ("virtio-blk-pci" , drives_table[i].devaddr); +qdev_init (qdev); unit_id++; }
Signature · 1 line
1.6.2.5
PATCH 3/8 qdev: add generic qdev_device_add()
In reply to Gerd HoffmannWill be used for -device command line.
--- hw/pci.c | 1 + hw/qdev.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ hw/qdev.h | 3 +++ 3 files changed, 55 insertions(+), 0 deletions(-)
hw/pci.c +1 -0
@@ -54,6 +54,7 @@ static struct BusInfo pci_bus_info = { .name = "PCI", .size = sizeof(PCIBus), .print = pcibus_dev_print, + .add = pci_create, .props = (Property []) { { .name ="devfn" ,
hw/qdev.c +51 -0
57 lines not on this page · raw message
hw/qdev.h +3 -0
@@ -29,11 +29,13 @@ struct DeviceState { };typedef void (*bus_dev_print )(Monitor *mon,DeviceState *dev,int indent); +typedef DeviceState * (*bus_dev_add )(const char *name,const char *addr);struct BusInfo {const char *name;size_t size;Property *props;bus_dev_print print; +bus_dev_add add; };struct BusState {
@@ -60,6 +62,7 @@ struct PropertyInfo {/*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create (BusState *bus,const char *name); +DeviceState *qdev_device_add (const char *cmdline);void qdev_init (DeviceState *dev);void qdev_free (DeviceState *dev);
Signature · 1 line
1.6.2.5
PATCH 4/8 qdev: add -device command line option.
In reply to Gerd HoffmannAdd a linked list where command line options can be saved. Use it for the new -device and for the -usbdevice and -bt switches.
--- hw/qdev.c | 4 ++- qemu-options.hx | 2 + vl.c | 96 ++++++++++++++++++++++++++++++++++++------------------- 3 files changed, 68 insertions(+), 34 deletions(-)
hw/qdev.c +3 -1
@@ -122,8 +122,10 @@ DeviceState *qdev_device_add(const char *cmdline)if (params) {while (params[0 ]) { -if (2 !=sscanf (params,"%31[^=]=%255[^,]%n" , tag, value, &n)) +if (2 !=sscanf (params,"%31[^=]=%255[^,]%n" , tag, value, &n)) { +fprintf (stderr,"parse error at \"%s\"\n" , params);break ; + } params += n;if (strcmp (tag,"addr" ) ==0 )continue ;
qemu-options.hx +2 -0
@@ -364,6 +364,8 @@ Network adapter that supports CDC ethernet and RNDIS protocols. @end table ETEXI +DEF("device", HAS_ARG, QEMU_OPTION_device, + "-device driver[,options] add device\n") DEF("name", HAS_ARG, QEMU_OPTION_name, "-name string set the name of the guest\n") STEXI
vl.c +63 -33
159 lines not on this page · raw message
Signature · 1 line
1.6.2.5
PATCH 5/8 qdev: add no_user, alias and desc
In reply to Gerd Hoffmannno_user: prevent users from adding certain devices.
desc: description of the device.
alias: to allow user friendly shortcuts on the command line, i.e.
-device usbmouse instead of -device "QEMU USB Mouse" or -device lsi instead of -device lsi53c895a
--- hw/qdev.c | 26 +++++++++++++++++++++++++- hw/qdev.h | 3 +++ 2 files changed, 28 insertions(+), 1 deletions(-)
hw/qdev.c +25 -1
@@ -50,6 +50,7 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name) {DeviceInfo *info; +/* first check device names */ for (info = device_info_list; info !=NULL ; info = info->next) {if (bus_info && info->bus_info != bus_info)continue ;
@@ -57,6 +58,17 @@ static DeviceInfo *qdev_find_info(BusInfo *bus_info, const char *name)continue ;return info; } + +/* failing that check the aliases */ +for (info = device_info_list; info !=NULL ; info = info->next) { +if (bus_info && info->bus_info != bus_info) +continue ; +if (!info->alias) +continue ; +if (strcmp (info->alias, name) !=0 ) +continue ; +return info; + }return NULL ; }
@@ -102,7 +114,14 @@ DeviceState *qdev_device_add(const char *cmdline) }if (strcmp (driver,"?" ) ==0 ) {for (info = device_info_list; info !=NULL ; info = info->next) { -fprintf (stderr,"name \"%s\", bus %s\n" , info->name, info->bus_info->name); +fprintf (stderr,"name \"%s\", bus %s" , info->name, info->bus_info->name); +if (info->alias) +fprintf (stderr,", alias \"%s\"" , info->alias); +if (info->desc) +fprintf (stderr,", desc \"%s\"" , info->desc); +if (info->no_user) +fprintf (stderr,", no-user" ); +fprintf (stderr,"\n" ); }return NULL ; }
@@ -117,6 +136,11 @@ DeviceState *qdev_device_add(const char *cmdline) info->bus_info->name);return NULL ; } +if (info->no_user) { +fprintf (stderr,"device \"%s\" can't be added via command line\n" , + info->name); +return NULL ; + } qdev = info->bus_info->add (driver,strlen (addr) ? addr :NULL );
hw/qdev.h +3 -0
@@ -79,8 +79,11 @@ typedef void (*SCSIAttachFn)(DeviceState *host, BlockDriverState *bdrv,struct DeviceInfo {const char *name; +const char *alias; +const char *desc;size_t size;Property *props; +int no_user;/* Private to qdev / bus. */ qdev_initfn init;
Signature · 1 line
1.6.2.5
PATCH 6/8 qdev: es1370 description
In reply to Gerd Hoffmann--- hw/es1370.c | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/es1370.c +1 -0
@@ -1054,6 +1054,7 @@ int es1370_init (PCIBus *bus)static PCIDeviceInfo es1370_info = { .qdev.name ="ES1370" , + .qdev.desc ="Ensoniq AudioPCI Sound Card" , .qdev.size =sizeof (PCIES1370State), .init = es1370_initfn, };
Signature · 1 line
1.6.2.5
PATCH 7/8 qdev: convert all vga
In reply to Gerd Hoffmann--- hw/cirrus_vga.c | 85 ++++++++++++++++++++++++++--------------------- hw/vga.c | 98 ++++++++++++++++++++++++++++++++++-------------------- hw/vmware_vga.c | 26 +++++++++++--- 3 files changed, 129 insertions(+), 80 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 +63 -37
115 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 8/8 qdev/pci: hook up i440fx.
In reply to Gerd HoffmannHook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev. Tag as no-user.
--- hw/pci_host.h | 3 ++ hw/piix_pci.c | 108 +++++++++++++++++++++++++++++++++++++++++++-------------- 2 files changed, 85 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 +82 -26
170 lines not on this page · raw message
Signature · 1 line
1.6.2.5