diff options
-rw-r--r-- | accel/accel.c | 1 | ||||
-rw-r--r-- | hw/core/qdev.c | 48 | ||||
-rw-r--r-- | include/hw/qdev-core.h | 2 | ||||
-rw-r--r-- | vl.c | 1 |
4 files changed, 41 insertions, 11 deletions
diff --git a/accel/accel.c b/accel/accel.c index 0d5b370dfd..8deb475b5d 100644 --- a/accel/accel.c +++ b/accel/accel.c @@ -66,6 +66,7 @@ static int accel_init_machine(AccelClass *acc, MachineState *ms) *(acc->allowed) = false; object_unref(OBJECT(accel)); } + object_set_accelerator_compat_props(acc->compat_props); return ret; } diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 512ce7ca7a..4f3200d54b 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -978,25 +978,51 @@ static void device_initfn(Object *obj) QLIST_INIT(&dev->gpios); } -void object_apply_compat_props(Object *obj) +/* + * Global property defaults + * Slot 0: accelerator's global property defaults + * Slot 1: machine's global property defaults + * Each is a GPtrArray of of GlobalProperty. + * Applied in order, later entries override earlier ones. + */ +static GPtrArray *object_compat_props[2]; + +/* + * Set machine's global property defaults to @compat_props. + * May be called at most once. + */ +void object_set_machine_compat_props(GPtrArray *compat_props) +{ + assert(!object_compat_props[1]); + object_compat_props[1] = compat_props; +} + +/* + * Set accelerator's global property defaults to @compat_props. + * May be called at most once. + */ +void object_set_accelerator_compat_props(GPtrArray *compat_props) { - if (object_dynamic_cast(qdev_get_machine(), TYPE_MACHINE)) { - MachineState *m = MACHINE(qdev_get_machine()); - MachineClass *mc = MACHINE_GET_CLASS(m); + assert(!object_compat_props[0]); + object_compat_props[0] = compat_props; +} - if (m->accelerator) { - AccelClass *ac = ACCEL_GET_CLASS(m->accelerator); +void object_apply_compat_props(Object *obj) +{ + int i; - if (ac->compat_props) { - object_apply_global_props(obj, ac->compat_props, &error_abort); - } - } - object_apply_global_props(obj, mc->compat_props, &error_abort); + for (i = 0; i < ARRAY_SIZE(object_compat_props); i++) { + object_apply_global_props(obj, object_compat_props[i], + &error_abort); } } static void device_post_init(Object *obj) { + /* + * Note: ordered so that the user's global properties take + * precedence. + */ object_apply_compat_props(obj); qdev_prop_set_globals(DEVICE(obj)); } diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 17f09aac72..aa8a3ea782 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -431,6 +431,8 @@ const char *qdev_fw_name(DeviceState *dev); Object *qdev_get_machine(void); +void object_set_machine_compat_props(GPtrArray *compat_props); +void object_set_accelerator_compat_props(GPtrArray *compat_props); void object_apply_compat_props(Object *obj); /* FIXME: make this a link<> */ @@ -3953,6 +3953,7 @@ int main(int argc, char **argv, char **envp) configure_rtc(qemu_find_opts_singleton("rtc")); machine_class = select_machine(); + object_set_machine_compat_props(machine_class->compat_props); set_memory_options(&ram_slots, &maxram_size, machine_class); |