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);