From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MOqRh-0007Y0-Js for qemu-devel@nongnu.org; Thu, 09 Jul 2009 06:01:41 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MOqRc-0007Rv-H8 for qemu-devel@nongnu.org; Thu, 09 Jul 2009 06:01:40 -0400 Received: from [199.232.76.173] (port=40399 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MOqRc-0007Rg-6w for qemu-devel@nongnu.org; Thu, 09 Jul 2009 06:01:36 -0400 Received: from mx2.redhat.com ([66.187.237.31]:46839) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MOqRb-0000AK-Eh for qemu-devel@nongnu.org; Thu, 09 Jul 2009 06:01:35 -0400 Message-ID: <4A55BFE7.4070402@redhat.com> Date: Thu, 09 Jul 2009 12:01:11 +0200 From: Gerd Hoffmann MIME-Version: 1.0 Subject: Re: [Qemu-devel] [PATCH 3/3 v2] Add a pc-0-10 machine type for compatibility with 0.10.x References: <1244821292.30522.56.camel@blaa> <4A3636FA.1040609@redhat.com> <20090615124101.GH6351@redhat.com> <4A364381.401@redhat.com> <4A364401.6010500@codemonkey.ws> <4A3647FB.9010808@redhat.com> <4A364B53.9080007@codemonkey.ws> <4A364FE0.40204@redhat.com> <4A3651EB.3070204@codemonkey.ws> <4A36555A.4090303@redhat.com> <4A3659A0.3050108@codemonkey.ws> <4A366348.1030202@redhat.com> <1245083229.3222.103.camel@blaa> <4A368F12.2090504@codemonkey.ws> <1246964898.2836.38.camel@blaa> <1246964950.2836.39.camel@blaa> <1246964998.2836.40.camel@blaa> <1246965054.2836.41.camel@blaa> <4A5338FC.9030301@redhat.com> <1247049984.3270.52.camel@blaa> <1247050083.3270.54.camel@blaa> <4A54986D.301@redhat.com> <4A54A2B0.6050605@codemonk! ey.ws> <4A54A895.5090501@redhat.com> <1247065728.3270.65.camel@blaa> <4A54EE87.2000508@redhat.com> <4A55136E.6050508@codemonkey.ws> <4A55A29A.9020202@redhat.com> <1247128775.22231.15.camel@blaa> <4A55B2E8.4060109@redhat.com> In-Reply-To: <4A55B2E8.4060109@redhat.com> Content-Type: multipart/mixed; boundary="------------020407020007040503020900" List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Mark McLoughlin Cc: Avi Kivity , qemu-devel@nongnu.org This is a multi-part message in MIME format. --------------020407020007040503020900 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, > I'd prefer to not introduce those virtio-$type-pci-$version devices in > the first place. It isn't hard to write up something qdev based. Only > problem is it will depend on lots of not-yet merged qdev patches. To back that with some code here is a quick patch. Not splitted up yet. Only virtio-blk is handled for demonstration purposes. Will not apply cleanly as it depends on both posted and not-yet posted patches in my patch queue. Once my qdev properties patch is in it should be easy to rebase to upstream/master though. cheers, Gerd --------------020407020007040503020900 Content-Type: text/plain; name="compat.diff" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="compat.diff" diff --git a/hw/boards.h b/hw/boards.h index f6733b7..5a07d07 100644 --- a/hw/boards.h +++ b/hw/boards.h @@ -17,6 +17,7 @@ typedef struct QEMUMachine { int use_scsi; int max_cpus; int is_default; + struct CompatProperty *compat_props; struct QEMUMachine *next; } QEMUMachine; diff --git a/hw/pc.c b/hw/pc.c index 38678da..cd64ccf 100644 --- a/hw/pc.c +++ b/hw/pc.c @@ -1460,6 +1460,21 @@ static QEMUMachine pc_machine = { .is_default = 1, }; +static QEMUMachine pc_machine_v0_10 = { + .name = "pc-0.10", + .desc = "Standard PC, qemu 0.10", + .init = pc_init_pci, + .max_cpus = 255, + .compat_props = (CompatProperty[]) { + { + .driver = "virtio-blk-pci", + .property = "class", + .value = "0x0180", /* PCI_CLASS_STORAGE_OTHER */ + }, + { /* end of list */ } + }, +}; + static QEMUMachine isapc_machine = { .name = "isapc", .desc = "ISA-only PC", @@ -1470,6 +1485,7 @@ static QEMUMachine isapc_machine = { static void pc_machine_init(void) { qemu_register_machine(&pc_machine); + qemu_register_machine(&pc_machine_v0_10); qemu_register_machine(&isapc_machine); } diff --git a/hw/qdev-properties.c b/hw/qdev-properties.c index 720001b..bec756d 100644 --- a/hw/qdev-properties.c +++ b/hw/qdev-properties.c @@ -228,3 +228,22 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props) } } +static CompatProperty *compat_props; + +void qdev_register_compat_props(CompatProperty *props) +{ + compat_props = props; +} + +void qdev_prop_set_compat(DeviceState *dev) +{ + CompatProperty *prop; + + if (!compat_props) + return; + for (prop = compat_props; prop->driver != NULL; prop++) { + if (strcmp(dev->info->name, prop->driver) != 0) + continue; + qdev_prop_parse(dev, prop->property, prop->value); + } +} diff --git a/hw/qdev.c b/hw/qdev.c index 9f7ac0b..ebb6bcf 100644 --- a/hw/qdev.c +++ b/hw/qdev.c @@ -130,6 +130,7 @@ DeviceState *qdev_create(BusState *bus, const char *name) dev->parent_bus = bus; qdev_prop_set_defaults(dev, dev->info->props); qdev_prop_set_defaults(dev, dev->parent_bus->info->props); + qdev_prop_set_compat(dev); LIST_INSERT_HEAD(&bus->children, dev, sibling); return dev; } diff --git a/hw/qdev.h b/hw/qdev.h index be10f44..5b4c1b0 100644 --- a/hw/qdev.h +++ b/hw/qdev.h @@ -8,6 +8,8 @@ typedef struct Property Property; typedef struct PropertyInfo PropertyInfo; +typedef struct CompatProperty CompatProperty; + typedef struct DeviceInfo DeviceInfo; typedef struct BusState BusState; @@ -63,6 +65,12 @@ struct PropertyInfo { int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len); }; +struct CompatProperty { + const char *driver; + const char *property; + const char *value; +}; + /*** Board API. This should go away once we have a machine config file. ***/ DeviceState *qdev_create(BusState *bus, const char *name); @@ -152,4 +160,7 @@ int qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value); int qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value); void qdev_prop_set_defaults(DeviceState *dev, Property *props); +void qdev_register_compat_props(CompatProperty *props); +void qdev_prop_set_compat(DeviceState *dev); + #endif diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 96f3764..996dadb 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -87,12 +87,7 @@ typedef struct { VirtIODevice *vdev; uint32_t addr; - uint16_t vendor; - uint16_t device; - uint16_t subvendor; - uint16_t class_code; - uint8_t pif; - + uint32_t class_code; qname hostlink; } VirtIOPCIProxy; @@ -421,12 +416,15 @@ static void virtio_blk_init_pci(PCIDevice *pci_dev) VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); VirtIODevice *vdev; + if (proxy->class_code != PCI_CLASS_STORAGE_SCSI && + proxy->class_code != PCI_CLASS_STORAGE_OTHER) + proxy->class_code = PCI_CLASS_STORAGE_SCSI; + vdev = virtio_blk_init(&pci_dev->qdev, proxy->hostlink); virtio_init_pci(proxy, vdev, PCI_VENDOR_ID_REDHAT_QUMRANET, PCI_DEVICE_ID_VIRTIO_BLOCK, - PCI_CLASS_STORAGE_OTHER, - 0x00); + proxy->class_code, 0x00); } static void virtio_console_init_pci(PCIDevice *pci_dev) @@ -478,6 +476,10 @@ static PCIDeviceInfo virtio_info[] = { .name = "drive", .info = &qdev_prop_name, .offset = offsetof(VirtIOPCIProxy, hostlink), + },{ + .name = "class", + .info = &qdev_prop_hex32, + .offset = offsetof(VirtIOPCIProxy, class_code), }, {/* end of list */} }, diff --git a/vl.c b/vl.c index 0acc1de..2c5608f 100644 --- a/vl.c +++ b/vl.c @@ -6030,6 +6030,8 @@ int main(int argc, char **argv, char **envp) module_call_init(MODULE_INIT_DEVICE); + if (machine->compat_props) + qdev_register_compat_props(machine->compat_props); machine->init(ram_size, boot_devices, kernel_filename, kernel_cmdline, initrd_filename, cpu_model); --------------020407020007040503020900--