Commit b6b611446077537b542c20804d3c850daff27845

Authored by Gerd Hoffmann
Committed by Anthony Liguori
1 parent 81ebb98b

qdev/compat: compat property infrastructure.

This add support for switching devices into a compatibility mode
using device properties.  Machine types can have a list of properties
for specific devices attached to allow the easy creation of machine
types compatible to older qemu versions.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/boards.h
... ... @@ -3,6 +3,8 @@
3 3 #ifndef HW_BOARDS_H
4 4 #define HW_BOARDS_H
5 5  
  6 +#include "qdev.h"
  7 +
6 8 typedef void QEMUMachineInitFunc(ram_addr_t ram_size,
7 9 const char *boot_device,
8 10 const char *kernel_filename,
... ... @@ -17,6 +19,7 @@ typedef struct QEMUMachine {
17 19 int use_scsi;
18 20 int max_cpus;
19 21 int is_default;
  22 + CompatProperty *compat_props;
20 23 struct QEMUMachine *next;
21 24 } QEMUMachine;
22 25  
... ...
hw/qdev-properties.c
... ... @@ -244,3 +244,26 @@ void qdev_prop_set_defaults(DeviceState *dev, Property *props)
244 244 }
245 245 }
246 246  
  247 +static CompatProperty *compat_props;
  248 +
  249 +void qdev_prop_register_compat(CompatProperty *props)
  250 +{
  251 + compat_props = props;
  252 +}
  253 +
  254 +void qdev_prop_set_compat(DeviceState *dev)
  255 +{
  256 + CompatProperty *prop;
  257 +
  258 + if (!compat_props) {
  259 + return;
  260 + }
  261 + for (prop = compat_props; prop->driver != NULL; prop++) {
  262 + if (strcmp(dev->info->name, prop->driver) != 0) {
  263 + continue;
  264 + }
  265 + if (qdev_prop_parse(dev, prop->property, prop->value) != 0) {
  266 + abort();
  267 + }
  268 + }
  269 +}
... ...
hw/qdev.c
... ... @@ -85,6 +85,7 @@ DeviceState *qdev_create(BusState *bus, const char *name)
85 85 dev->parent_bus = bus;
86 86 qdev_prop_set_defaults(dev, dev->info->props);
87 87 qdev_prop_set_defaults(dev, dev->parent_bus->info->props);
  88 + qdev_prop_set_compat(dev);
88 89 LIST_INSERT_HEAD(&bus->children, dev, sibling);
89 90 return dev;
90 91 }
... ...
hw/qdev.h
... ... @@ -8,6 +8,8 @@ typedef struct Property Property;
8 8  
9 9 typedef struct PropertyInfo PropertyInfo;
10 10  
  11 +typedef struct CompatProperty CompatProperty;
  12 +
11 13 typedef struct DeviceInfo DeviceInfo;
12 14  
13 15 typedef struct BusState BusState;
... ... @@ -68,6 +70,12 @@ struct PropertyInfo {
68 70 int (*print)(DeviceState *dev, Property *prop, char *dest, size_t len);
69 71 };
70 72  
  73 +struct CompatProperty {
  74 + const char *driver;
  75 + const char *property;
  76 + const char *value;
  77 +};
  78 +
71 79 /*** Board API. This should go away once we have a machine config file. ***/
72 80  
73 81 DeviceState *qdev_create(BusState *bus, const char *name);
... ... @@ -147,4 +155,7 @@ void qdev_prop_set_uint32(DeviceState *dev, const char *name, uint32_t value);
147 155 void qdev_prop_set_ptr(DeviceState *dev, const char *name, void *value);
148 156 void qdev_prop_set_defaults(DeviceState *dev, Property *props);
149 157  
  158 +void qdev_prop_register_compat(CompatProperty *props);
  159 +void qdev_prop_set_compat(DeviceState *dev);
  160 +
150 161 #endif
... ...
... ... @@ -5946,6 +5946,9 @@ int main(int argc, char **argv, char **envp)
5946 5946  
5947 5947 module_call_init(MODULE_INIT_DEVICE);
5948 5948  
  5949 + if (machine->compat_props) {
  5950 + qdev_prop_register_compat(machine->compat_props);
  5951 + }
5949 5952 machine->init(ram_size, boot_devices,
5950 5953 kernel_filename, kernel_cmdline, initrd_filename, cpu_model);
5951 5954  
... ...