qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH 0/8] qdev patches, batch #2
@ 2009-07-01  8:57 Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 1/8] qdev: factor out driver search to qdev_find_info() Gerd Hoffmann
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

  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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 1/8] qdev: factor out driver search to qdev_find_info()
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 2/8] qdev/pci: make pci_create return DeviceState instead of PCIDevice Gerd Hoffmann
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index ca43325..23cfab9 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -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);
     }
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 2/8] qdev/pci: make pci_create return DeviceState instead of PCIDevice.
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 1/8] qdev: factor out driver search to qdev_find_info() Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 3/8] qdev: add generic qdev_device_add() Gerd Hoffmann
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Rationale: wanna use it as callback in qdev code.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 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(-)

diff --git a/hw/pc.c b/hw/pc.c
index bdcec52..2b89356 100644
--- a/hw/pc.c
+++ b/hw/pc.c
@@ -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 */
diff --git a/hw/pci-hotplug.c b/hw/pci-hotplug.c
index d0f2911..0781b52 100644
--- a/hw/pci-hotplug.c
+++ b/hw/pci-hotplug.c
@@ -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,
diff --git a/hw/pci.c b/hw/pci.c
index 0952d9b..3c20aa2 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -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);
         }
     }
 
diff --git a/hw/pci.h b/hw/pci.h
index cbfea6a..17563ed 100644
--- a/hw/pci.h
+++ b/hw/pci.h
@@ -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 */
diff --git a/hw/ppc440_bamboo.c b/hw/ppc440_bamboo.c
index d9ef3ec..b6b8f8a 100644
--- a/hw/ppc440_bamboo.c
+++ b/hw/ppc440_bamboo.c
@@ -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++;
         }
 
diff --git a/hw/ppce500_mpc8544ds.c b/hw/ppce500_mpc8544ds.c
index c0e367d..d21eb95 100644
--- a/hw/ppce500_mpc8544ds.c
+++ b/hw/ppce500_mpc8544ds.c
@@ -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++;
         }
 
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 3/8] qdev: add generic qdev_device_add()
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 1/8] qdev: factor out driver search to qdev_find_info() Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 2/8] qdev/pci: make pci_create return DeviceState instead of PCIDevice Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 4/8] qdev: add -device command line option Gerd Hoffmann
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Will be used for -device command line.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci.c  |    1 +
 hw/qdev.c |   51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 hw/qdev.h |    3 +++
 3 files changed, 55 insertions(+), 0 deletions(-)

diff --git a/hw/pci.c b/hw/pci.c
index 3c20aa2..ef1877a 100644
--- a/hw/pci.c
+++ b/hw/pci.c
@@ -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",
diff --git a/hw/qdev.c b/hw/qdev.c
index 23cfab9..c691b8d 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -87,6 +87,57 @@ DeviceState *qdev_create(BusState *bus, const char *name)
     return dev;
 }
 
+DeviceState *qdev_device_add(const char *cmdline)
+{
+    DeviceInfo *info;
+    DeviceState *qdev;
+    char driver[32], addr[32] = "";
+    char tag[32], value[256];
+    const char *params = NULL;
+    int n = 0;
+
+    if (1 != sscanf(cmdline, "%32[^,],%n", driver, &n)) {
+        fprintf(stderr, "device parse error: \"%s\"\n", cmdline);
+        return NULL;
+    }
+    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);
+        }
+        return NULL;
+    }
+    if (n) {
+        params = cmdline + n;
+        get_param_value(addr, sizeof(addr), "addr", params);
+    }
+    info = qdev_find_info(NULL, driver);
+
+    if (!info->bus_info->add) {
+        fprintf(stderr, "bus \"%s\" can't add devices.\n",
+                info->bus_info->name);
+        return NULL;
+    }
+
+    qdev = info->bus_info->add(driver, strlen(addr) ? addr : NULL);
+
+    if (params) {
+        while (params[0]) {
+            if (2 != sscanf(params, "%31[^=]=%255[^,]%n", tag, value, &n))
+                break;
+            params += n;
+            if (strcmp(tag, "addr") == 0)
+                continue;
+            if (-1 == qdev_prop_parse(qdev, tag, value)) {
+                fprintf(stderr, "can't set property \"%s\" to \"%s\" for \"%s\"\n",
+                        tag, value, driver);
+            }
+        }
+    }
+
+    qdev_init(qdev);
+    return qdev;
+}
+
 /* Initialize a device.  Device properties should be set before calling
    this function.  IRQs and MMIO regions should be connected/mapped after
    calling this function.  */
diff --git a/hw/qdev.h b/hw/qdev.h
index d117be8..13cafe5 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -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);
 
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 4/8] qdev: add -device command line option.
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
                   ` (2 preceding siblings ...)
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 3/8] qdev: add generic qdev_device_add() Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 5/8] qdev: add no_user, alias and desc Gerd Hoffmann
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Add a linked list where command line options can be saved.
Use it for the new -device and for the -usbdevice and -bt switches.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c       |    4 ++-
 qemu-options.hx |    2 +
 vl.c            |   96 ++++++++++++++++++++++++++++++++++++-------------------
 3 files changed, 68 insertions(+), 34 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index c691b8d..042c7f7 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -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;
diff --git a/qemu-options.hx b/qemu-options.hx
index a94f9d3..67d7bd0 100644
--- a/qemu-options.hx
+++ b/qemu-options.hx
@@ -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
diff --git a/vl.c b/vl.c
index 7b7489c..ca82f80 100644
--- a/vl.c
+++ b/vl.c
@@ -181,12 +181,6 @@ int main(int argc, char **argv)
 
 #define DEFAULT_RAM_SIZE 128
 
-/* Max number of USB devices that can be specified on the commandline.  */
-#define MAX_USB_CMDLINE 8
-
-/* Max number of bluetooth switches on the commandline.  */
-#define MAX_BT_CMDLINE 10
-
 /* XXX: use a two level table to limit memory usage */
 #define MAX_IOPORTS 65536
 
@@ -2787,6 +2781,11 @@ static int usb_device_del(const char *devname)
     return usb_device_del_addr(bus_num, addr);
 }
 
+static int usb_parse(const char *cmdline)
+{
+    return usb_device_add(cmdline, 0);
+}
+
 void do_usb_add(Monitor *mon, const char *devname)
 {
     usb_device_add(devname, 1);
@@ -4970,6 +4969,52 @@ char *qemu_find_file(int type, const char *name)
     return buf;
 }
 
+struct device_config {
+    enum {
+        DEV_GENERIC,   /* -device      */
+        DEV_USB,       /* -usbdevice   */
+        DEV_BT,        /* -bt          */
+    } type;
+    const char *cmdline;
+    TAILQ_ENTRY(device_config) next;
+};
+TAILQ_HEAD(, device_config) device_configs = TAILQ_HEAD_INITIALIZER(device_configs);
+
+static void add_device_config(int type, const char *cmdline)
+{
+    struct device_config *conf;
+
+    conf = qemu_mallocz(sizeof(*conf));
+    conf->type = type;
+    conf->cmdline = cmdline;
+    TAILQ_INSERT_TAIL(&device_configs, conf, next);
+}
+
+static int foreach_device_config(int type, int (*func)(const char *cmdline))
+{
+    struct device_config *conf;
+    int rc;
+
+    TAILQ_FOREACH(conf, &device_configs, next) {
+        if (conf->type != type)
+            continue;
+        rc = func(conf->cmdline);
+        if (0 != rc)
+            return rc;
+    }
+    return 0;
+}
+
+static int generic_parse(const char *cmdline)
+{
+    DeviceState *dev;
+
+    dev = qdev_device_add(cmdline);
+    if (!dev)
+        return -1;
+    return 0;
+}
+
 int main(int argc, char **argv, char **envp)
 {
     const char *gdbstub_dev = NULL;
@@ -4984,8 +5029,6 @@ int main(int argc, char **argv, char **envp)
     int cyls, heads, secs, translation;
     const char *net_clients[MAX_NET_CLIENTS];
     int nb_net_clients;
-    const char *bt_opts[MAX_BT_CMDLINE];
-    int nb_bt_opts;
     int hda_index;
     int optind;
     const char *r, *optarg;
@@ -5000,8 +5043,6 @@ int main(int argc, char **argv, char **envp)
     const char *loadvm = NULL;
     QEMUMachine *machine;
     const char *cpu_model;
-    const char *usb_devices[MAX_USB_CMDLINE];
-    int usb_devices_index;
 #ifndef _WIN32
     int fds[2];
 #endif
@@ -5081,10 +5122,7 @@ int main(int argc, char **argv, char **envp)
         node_cpumask[i] = 0;
     }
 
-    usb_devices_index = 0;
-
     nb_net_clients = 0;
-    nb_bt_opts = 0;
     nb_drives = 0;
     nb_drives_opt = 0;
     nb_numa_nodes = 0;
@@ -5331,11 +5369,7 @@ int main(int argc, char **argv, char **envp)
                 break;
 #endif
             case QEMU_OPTION_bt:
-                if (nb_bt_opts >= MAX_BT_CMDLINE) {
-                    fprintf(stderr, "qemu: too many bluetooth options\n");
-                    exit(1);
-                }
-                bt_opts[nb_bt_opts++] = optarg;
+                add_device_config(DEV_BT, optarg);
                 break;
 #ifdef HAS_AUDIO
             case QEMU_OPTION_audio_help:
@@ -5577,12 +5611,10 @@ int main(int argc, char **argv, char **envp)
                 break;
             case QEMU_OPTION_usbdevice:
                 usb_enabled = 1;
-                if (usb_devices_index >= MAX_USB_CMDLINE) {
-                    fprintf(stderr, "Too many USB devices\n");
-                    exit(1);
-                }
-                usb_devices[usb_devices_index] = optarg;
-                usb_devices_index++;
+                add_device_config(DEV_USB, optarg);
+                break;
+            case QEMU_OPTION_device:
+                add_device_config(DEV_GENERIC, optarg);
                 break;
             case QEMU_OPTION_smp:
                 smp_cpus = atoi(optarg);
@@ -5893,9 +5925,8 @@ int main(int argc, char **argv, char **envp)
     net_client_check();
 
     /* init the bluetooth world */
-    for (i = 0; i < nb_bt_opts; i++)
-        if (bt_parse(bt_opts[i]))
-            exit(1);
+    if (foreach_device_config(DEV_BT, bt_parse))
+        exit(1);
 
     /* init the memory */
     if (ram_size == 0)
@@ -6083,14 +6114,13 @@ int main(int argc, char **argv, char **envp)
 
     /* init USB devices */
     if (usb_enabled) {
-        for(i = 0; i < usb_devices_index; i++) {
-            if (usb_device_add(usb_devices[i], 0) < 0) {
-                fprintf(stderr, "Warning: could not add USB device %s\n",
-                        usb_devices[i]);
-            }
-        }
+        foreach_device_config(DEV_USB, usb_parse);
     }
 
+    /* init generic devices */
+    if (foreach_device_config(DEV_GENERIC, generic_parse))
+        exit(1);
+
     if (!display_state)
         dumb_display_init();
     /* just use the first displaystate for the moment */
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 5/8] qdev: add no_user, alias and desc
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
                   ` (3 preceding siblings ...)
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 4/8] qdev: add -device command line option Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 6/8] qdev: es1370 description Gerd Hoffmann
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

no_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

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/qdev.c |   26 +++++++++++++++++++++++++-
 hw/qdev.h |    3 +++
 2 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/hw/qdev.c b/hw/qdev.c
index 042c7f7..48d0fb9 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -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);
 
diff --git a/hw/qdev.h b/hw/qdev.h
index 13cafe5..f81e850 100644
--- a/hw/qdev.h
+++ b/hw/qdev.h
@@ -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;
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 6/8] qdev: es1370 description
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
                   ` (4 preceding siblings ...)
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 5/8] qdev: add no_user, alias and desc Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 7/8] qdev: convert all vga Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 8/8] qdev/pci: hook up i440fx Gerd Hoffmann
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/es1370.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

diff --git a/hw/es1370.c b/hw/es1370.c
index baad7cc..0cfdb76 100644
--- a/hw/es1370.c
+++ b/hw/es1370.c
@@ -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,
 };
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 7/8] qdev: convert all vga
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
                   ` (5 preceding siblings ...)
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 6/8] qdev: es1370 description Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 8/8] qdev/pci: hook up i440fx Gerd Hoffmann
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann


Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/cirrus_vga.c |   85 ++++++++++++++++++++++++++---------------------
 hw/vga.c        |   98 ++++++++++++++++++++++++++++++++++--------------------
 hw/vmware_vga.c |   26 +++++++++++---
 3 files changed, 129 insertions(+), 80 deletions(-)

diff --git a/hw/cirrus_vga.c b/hw/cirrus_vga.c
index 902b3ee..1d800e9 100644
--- a/hw/cirrus_vga.c
+++ b/hw/cirrus_vga.c
@@ -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);
diff --git a/hw/vga.c b/hw/vga.c
index 403f6ff..e1a470d 100644
--- a/hw/vga.c
+++ b/hw/vga.c
@@ -2480,52 +2480,78 @@ static void pci_vga_write_config(PCIDevice *d,
         s->map_addr = 0;
 }
 
-int pci_vga_init(PCIBus *bus,
-                 unsigned long vga_bios_offset, int vga_bios_size)
-{
-    PCIVGAState *d;
-    VGAState *s;
-    uint8_t *pci_conf;
-
-    d = (PCIVGAState *)pci_register_device(bus, "VGA",
-                                           sizeof(PCIVGAState),
-                                           -1, NULL, pci_vga_write_config);
-    if (!d)
-        return -1;
-    s = &d->vga_state;
-
-    vga_common_init(s, VGA_RAM_SIZE);
-    vga_init(s);
-
-    s->ds = graphic_console_init(s->update, s->invalidate,
-                                 s->screen_dump, s->text_update, s);
-
-    s->pci_dev = &d->dev;
-
-    pci_conf = d->dev.config;
-    // dummy VGA (same as Bochs ID)
-    pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
-    pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
-    pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
-    pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
-
-    /* XXX: VGA_RAM_SIZE must be a power of two */
-    pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
-                           PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
-    if (vga_bios_size != 0) {
+static void pci_vga_initfn(PCIDevice *dev)
+{
+     PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
+     VGAState *s = &d->vga_state;
+     uint8_t *pci_conf = d->dev.config;
+
+     // vga + console init
+     vga_common_init(s, VGA_RAM_SIZE);
+     vga_init(s);
+     s->pci_dev = &d->dev;
+     s->ds = graphic_console_init(s->update, s->invalidate,
+                                  s->screen_dump, s->text_update, s);
+
+     // dummy VGA (same as Bochs ID)
+     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
+     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
+     pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
+     pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
+
+     /* XXX: VGA_RAM_SIZE must be a power of two */
+     pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
+                      PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
+
+     if (s->bios_size) {
         unsigned int bios_total_size;
-        s->bios_offset = vga_bios_offset;
-        s->bios_size = vga_bios_size;
         /* must be a power of two */
         bios_total_size = 1;
-        while (bios_total_size < vga_bios_size)
+        while (bios_total_size < s->bios_size)
             bios_total_size <<= 1;
         pci_register_bar(&d->dev, PCI_ROM_SLOT, bios_total_size,
-                               PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
+                         PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
     }
+}
+
+int pci_vga_init(PCIBus *bus,
+                 unsigned long vga_bios_offset, int vga_bios_size)
+{
+    DeviceState *qdev;
+
+    qdev = pci_create("VGA", NULL);
+    qdev_prop_set_uint32(qdev, "bios-offset", vga_bios_offset);
+    qdev_prop_set_uint32(qdev, "bios-size", vga_bios_offset);
+    qdev_init(qdev);
+
     return 0;
 }
 
+static PCIDeviceInfo vga_info = {
+    .qdev.name    = "VGA",
+    .qdev.size    = sizeof(PCIVGAState),
+    .init         = pci_vga_initfn,
+    .config_write = pci_vga_write_config,
+    .qdev.props   = (Property[]) {
+        {
+            .name   = "bios-offset",
+            .info   = &qdev_prop_hex32,
+            .offset = offsetof(PCIVGAState, vga_state.bios_offset),
+        },{
+            .name   = "bios-size",
+            .info   = &qdev_prop_hex32,
+            .offset = offsetof(PCIVGAState, vga_state.bios_size),
+        },
+        {/* end of list */}
+    }
+};
+
+static void vga_register(void)
+{
+    pci_qdev_register(&vga_info);
+}
+device_init(vga_register);
+
 /********************************************************/
 /* vga screen dump */
 
diff --git a/hw/vmware_vga.c b/hw/vmware_vga.c
index accdac4..5ceebf1 100644
--- a/hw/vmware_vga.c
+++ b/hw/vmware_vga.c
@@ -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);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [Qemu-devel] [PATCH 8/8] qdev/pci: hook up i440fx.
  2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
                   ` (6 preceding siblings ...)
  2009-07-01  8:57 ` [Qemu-devel] [PATCH 7/8] qdev: convert all vga Gerd Hoffmann
@ 2009-07-01  8:57 ` Gerd Hoffmann
  7 siblings, 0 replies; 9+ messages in thread
From: Gerd Hoffmann @ 2009-07-01  8:57 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

Hook i44fx pcihost into sysbus.
Convert Host bridge and ISA bridge pci devices to qdev.
Tag as no-user.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/pci_host.h |    3 ++
 hw/piix_pci.c |  108 +++++++++++++++++++++++++++++++++++++++++++--------------
 2 files changed, 85 insertions(+), 26 deletions(-)

diff --git a/hw/pci_host.h b/hw/pci_host.h
index 757b0e2..48862b5 100644
--- a/hw/pci_host.h
+++ b/hw/pci_host.h
@@ -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;
diff --git a/hw/piix_pci.c b/hw/piix_pci.c
index fce01d4..a5d42d1 100644
--- a/hw/piix_pci.c
+++ b/hw/piix_pci.c
@@ -25,6 +25,7 @@
 #include "hw.h"
 #include "pc.h"
 #include "pci.h"
+#include "sysbus.h"
 
 typedef uint32_t pci_addr_t;
 #include "pci_host.h"
@@ -169,16 +170,9 @@ static int i440fx_load(QEMUFile* f, void *opaque, int version_id)
     return 0;
 }
 
-PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+static void i440fx_pcihost_initfn(SysBusDevice *dev)
 {
-    PCIBus *b;
-    PCIDevice *d;
-    I440FXState *s;
-
-    s = qemu_mallocz(sizeof(I440FXState));
-    b = pci_register_bus(NULL, "pci", 
-                         piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
-    s->bus = b;
+    I440FXState *s = FROM_SYSBUS(I440FXState, dev);
 
     register_ioport_write(0xcf8, 4, 4, i440fx_addr_writel, s);
     register_ioport_read(0xcf8, 4, 4, i440fx_addr_readl, s);
@@ -189,10 +183,10 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
     register_ioport_read(0xcfc, 4, 1, pci_host_data_readb, s);
     register_ioport_read(0xcfc, 4, 2, pci_host_data_readw, s);
     register_ioport_read(0xcfc, 4, 4, pci_host_data_readl, s);
+}
 
-    d = pci_register_device(b, "i440FX", sizeof(PCIDevice), 0,
-                            NULL, i440fx_write_config);
-
+static void i440fx_initfn(PCIDevice *d)
+{
     pci_config_set_vendor_id(d->config, PCI_VENDOR_ID_INTEL);
     pci_config_set_device_id(d->config, PCI_DEVICE_ID_INTEL_82441);
     d->config[0x08] = 0x02; // revision
@@ -202,7 +196,25 @@ PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
     d->config[0x72] = 0x02; /* SMRAM */
 
     register_savevm("I440FX", 0, 2, i440fx_save, i440fx_load, d);
+}
+
+PCIBus *i440fx_init(PCIDevice **pi440fx_state, qemu_irq *pic)
+{
+    DeviceState *dev;
+    PCIBus *b;
+    PCIDevice *d;
+    I440FXState *s;
+
+    dev = qdev_create(NULL, "i440FX-pcihost");
+    s = FROM_SYSBUS(I440FXState, sysbus_from_qdev(dev));
+    b = pci_register_bus(&s->busdev.qdev, "pci",
+                         piix3_set_irq, pci_slot_get_pirq, pic, 0, 4);
+    s->bus = b;
+    qdev_init(dev);
+
+    d = pci_create_simple(b, 0, "i440FX");
     *pi440fx_state = d;
+
     return b;
 }
 
@@ -326,49 +338,93 @@ static int piix_load(QEMUFile* f, void *opaque, int version_id)
     return pci_device_load(d, f);
 }
 
-int piix3_init(PCIBus *bus, int devfn)
+static void piix3_initfn(PCIDevice *d)
 {
-    PCIDevice *d;
     uint8_t *pci_conf;
 
-    d = pci_register_device(bus, "PIIX3", sizeof(PCIDevice),
-                                    devfn, NULL, NULL);
     register_savevm("PIIX3", 0, 2, piix_save, piix_load, d);
 
-    piix3_dev = d;
     pci_conf = d->config;
-
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371SB_0); // 82371SB PIIX3 PCI-to-ISA bridge (Step A1)
     pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
     pci_conf[PCI_HEADER_TYPE] =
         PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
 
+    piix3_dev = d;
     piix3_reset(d);
     qemu_register_reset(piix3_reset, d);
-    return d->devfn;
 }
 
-int piix4_init(PCIBus *bus, int devfn)
+static void piix4_initfn(PCIDevice *d)
 {
-    PCIDevice *d;
     uint8_t *pci_conf;
 
-    d = pci_register_device(bus, "PIIX4", sizeof(PCIDevice),
-                                    devfn, NULL, NULL);
     register_savevm("PIIX4", 0, 2, piix_save, piix_load, d);
 
-    piix4_dev = d;
     pci_conf = d->config;
-
     pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_INTEL);
     pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_INTEL_82371AB_0); // 82371AB/EB/MB PIIX4 PCI-to-ISA bridge
     pci_config_set_class(pci_conf, PCI_CLASS_BRIDGE_ISA);
     pci_conf[PCI_HEADER_TYPE] =
         PCI_HEADER_TYPE_NORMAL | PCI_HEADER_TYPE_MULTI_FUNCTION; // header_type = PCI_multifunction, generic
 
-
+    piix4_dev = d;
     piix4_reset(d);
     qemu_register_reset(piix4_reset, d);
+}
+
+int piix3_init(PCIBus *bus, int devfn)
+{
+    PCIDevice *d;
+
+    d = pci_create_simple(bus, devfn, "PIIX3");
     return d->devfn;
 }
+
+int piix4_init(PCIBus *bus, int devfn)
+{
+    PCIDevice *d;
+
+    d = pci_create_simple(bus, devfn, "PIIX4");
+    return d->devfn;
+}
+
+static PCIDeviceInfo i440fx_info[] = {
+    {
+        .qdev.name    = "i440FX",
+        .qdev.desc    = "Host bridge",
+        .qdev.size    = sizeof(PCIDevice),
+        .qdev.no_user = 1,
+        .init         = i440fx_initfn,
+        .config_write = i440fx_write_config,
+    },{
+        .qdev.name    = "PIIX3",
+        .qdev.desc    = "ISA bridge",
+        .qdev.size    = sizeof(PCIDevice),
+        .qdev.no_user = 1,
+        .init         = piix3_initfn,
+    },{
+        .qdev.name    = "PIIX4",
+        .qdev.desc    = "ISA bridge",
+        .qdev.size    = sizeof(PCIDevice),
+        .qdev.no_user = 1,
+        .init         = piix4_initfn,
+    },{
+        /* end of list */
+    }
+};
+
+static SysBusDeviceInfo i440fx_pcihost_info = {
+    .init         = i440fx_pcihost_initfn,
+    .qdev.name    = "i440FX-pcihost",
+    .qdev.size    = sizeof(I440FXState),
+    .qdev.no_user = 1,
+};
+
+static void i440fx_register(void)
+{
+    sysbus_register_withprop(&i440fx_pcihost_info);
+    pci_qdev_register_many(i440fx_info);
+}
+device_init(i440fx_register);
-- 
1.6.2.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2009-07-01  8:57 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-07-01  8:57 [Qemu-devel] [PATCH 0/8] qdev patches, batch #2 Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 1/8] qdev: factor out driver search to qdev_find_info() Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 2/8] qdev/pci: make pci_create return DeviceState instead of PCIDevice Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 3/8] qdev: add generic qdev_device_add() Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 4/8] qdev: add -device command line option Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 5/8] qdev: add no_user, alias and desc Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 6/8] qdev: es1370 description Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 7/8] qdev: convert all vga Gerd Hoffmann
2009-07-01  8:57 ` [Qemu-devel] [PATCH 8/8] qdev/pci: hook up i440fx Gerd Hoffmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).