~pmdj/ubuntu/trusty/qemu/2.9+applesmc+fadtv3

« back to all changes in this revision

Viewing changes to hw/core/qdev.c

  • Committer: Phil Dennis-Jordan
  • Date: 2017-07-21 08:03:43 UTC
  • mfrom: (1.1.1)
  • Revision ID: phil@philjordan.eu-20170721080343-2yr2vdj7713czahv
New upstream release 2.9.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
37
37
#include "hw/boards.h"
38
38
#include "hw/sysbus.h"
39
39
#include "qapi-event.h"
 
40
#include "migration/migration.h"
40
41
 
41
42
int qdev_hotplug = 0;
42
43
static bool qdev_hot_added = false;
102
103
 
103
104
void qdev_set_parent_bus(DeviceState *dev, BusState *bus)
104
105
{
 
106
    bool replugging = dev->parent_bus != NULL;
 
107
 
 
108
    if (replugging) {
 
109
        /* Keep a reference to the device while it's not plugged into
 
110
         * any bus, to avoid it potentially evaporating when it is
 
111
         * dereffed in bus_remove_child().
 
112
         */
 
113
        object_ref(OBJECT(dev));
 
114
        bus_remove_child(dev->parent_bus, dev);
 
115
        object_unref(OBJECT(dev->parent_bus));
 
116
    }
105
117
    dev->parent_bus = bus;
106
118
    object_ref(OBJECT(bus));
107
119
    bus_add_child(bus, dev);
 
120
    if (replugging) {
 
121
        object_unref(OBJECT(dev));
 
122
    }
108
123
}
109
124
 
110
125
/* Create a new device.  This only initializes the device state
889
904
    Error *local_err = NULL;
890
905
    bool unattached_parent = false;
891
906
    static int unattached_count;
 
907
    int ret;
892
908
 
893
909
    if (dev->hotplugged && !dc->hotpluggable) {
894
910
        error_setg(errp, QERR_DEVICE_NO_HOTPLUG, object_get_typename(obj));
896
912
    }
897
913
 
898
914
    if (value && !dev->realized) {
 
915
        ret = check_migratable(obj, &local_err);
 
916
        if (ret < 0) {
 
917
            goto fail;
 
918
        }
 
919
 
899
920
        if (!obj->parent) {
900
921
            gchar *name = g_strdup_printf("device[%d]", unattached_count++);
901
922
 
933
954
        }
934
955
 
935
956
        if (qdev_get_vmsd(dev)) {
936
 
            vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
937
 
                                           dev->instance_id_alias,
938
 
                                           dev->alias_required_for_version);
 
957
            if (vmstate_register_with_alias_id(dev, -1, qdev_get_vmsd(dev), dev,
 
958
                                               dev->instance_id_alias,
 
959
                                               dev->alias_required_for_version,
 
960
                                               &local_err) < 0) {
 
961
                goto post_realize_fail;
 
962
            }
939
963
        }
940
964
 
941
965
        QLIST_FOREACH(bus, &dev->child_bus, sibling) {