aboutsummaryrefslogtreecommitdiff
path: root/hw/qdev.c
AgeCommit message (Collapse)AuthorFilesLines
2012-12-06qdev: qdev_create(): use error_report() instead of hw_error()Eduardo Habkost1-3/+5
hw_error() is specific for fatal hardware emulation errors, not for internal errors related to the qdev object/class abstraction or object initialization. Replace it with an error_report() call, followed by abort(). This will also help reduce dependencies of the qdev code (as hw_error() is from cpus.o, and depends on the CPU list from exec.o). Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-11-26qdev: simplify (de)allocation of busesPaolo Bonzini1-9/+1
All conditional deallocation can now be done with object_delete. Remove the @qom_allocated and @glib_allocated fields; replace the latter with a direct assignment of the @free function pointer. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-11-26qdev: move bus removal to object_unparentPaolo Bonzini1-3/+13
Add an ObjectClass method that is done at object_unparent time. It should remove any backlinks to the object in the composition tree, so that object_delete will be able to drop the last reference and free the object. Use it for qdev buses. Reviewed-by: Andreas Färber <afaerber@suse.de> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-11-15qdev: Split up header so it can be used in cpu.hAnthony Liguori1-0/+1
Header file dependency is a frickin' nightmare right now. cpu.h tends to get included in our 'include everything' header files but qdev also needs to include those headers mainly for qdev-properties since it knows about CharDriverState and friends. We can solve this for now by splitting out qdev.h along the same lines that we previously split the C file. Then cpu.h just needs to include qdev-core.h. hw/qdev.h is split into following new headers: hw/qdev-core.h hw/qdev-properties.h hw/qdev-monitor.h Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> [ehabkost: re-add DEFINE_PROP_PCI_HOST_DEVADDR, that was removed on the original patch (by mistake, I guess)] [ehabkost: kill qdev_prop_set_vlan() declaration] [ehabkost: moved get_fw_dev_path() comment to the original location (I don't know why it was moved)] [ehabkost: removed qdev_exists() declaration] [ehabkost: keep using 'QemuOpts' instead of 'struct QemuOpts', as qdev-core.h includes qemu-option.h] Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-10-10qdev: allow multiple qdev_init_gpio_in() callsPeter A. G. Crosthwaite1-3/+3
Allow multiple qdev_init_gpio_in() calls for the one device. The first call will define GPIOs 0-N-1, the next GPIOs N- ... . Allows different GPIOs to be handled with different handlers. Needed when two levels of the QOM class heirachy both define GPIO functionality, as a single GPIO handler with an index selecter is not possible. Signed-off-by: Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
2012-10-06Merge branch 'trivial-patches' of git://github.com/stefanha/qemuAurelien Jarno1-1/+0
* 'trivial-patches' of git://github.com/stefanha/qemu: versatilepb: Use symbolic indices for ARM PIC qdev: kill bogus comment qemu-barrier: Fix compiler version check for future gcc versions hw: Add missing 'static' attribute for QEMUMachine cleanup useless return sentence qemu-sockets: Fix compiler warning (regression for MinGW) vnc: Fix spelling (hellmen -> hellman) in comment slirp: Fix spelling in comment (enought -> enough, insure -> ensure) tcg/arm: Use tcg_out_mov_reg rather than inline equivalent code cpu: Add missing 'static' attribute to qemu_global_mutex configure: Support empty target list (--target-list=) hw: Fix return value check for bdrv_read, bdrv_write
2012-10-06vl.c: convert *vga_enabled functions to QOMAurelien Jarno1-5/+0
And get rid of qdev_exists(). Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2012-10-05qdev: kill bogus commentEduardo Habkost1-1/+0
When the DeviceInfo code was removed, the comment describing qdev_subclass_init() was left in the code by mistake. Remove it. Cc: qemu-trivial@nongnu.org Signed-off-by: Eduardo Habkost <ehabkost@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@gmail.com>
2012-10-05scsi, pci, qdev, isa-bus, sysbus: don't let *_get_fw_dev_path return NULLJim Meyering1-1/+1
Use g_strdup rather than strdup, because the sole caller (qdev_get_fw_dev_path_helper) assumes it gets non-NULL, and dereferences it. Besides, in that caller, the allocated buffer is already freed with g_free, so it's better to allocate with a matching g_strdup. In one case, (scsi-bus.c) it was trivial, so I replaced an snprintf+ g_strdup combination with an equivalent g_strdup_printf use. Signed-off-by: Jim Meyering <meyering@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-08-23qom: object_delete should unparent the object firstPaolo Bonzini1-2/+0
object_deinit is only called when the reference count goes to zero, and yet tries to do an object_unparent. Now, object_unparent either does nothing or it will decrease the reference count. Because we know the reference count is zero, the object_unparent call in object_deinit is useless. Instead, we need to disconnect the object from its parent just before we remove the last reference apart from the parent's. This happens in object_delete. Once we do this, all calls to object_unparent peppered through QEMU can go away. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-08-01net: Remove VLANStateStefan Hajnoczi1-2/+0
VLANState is no longer used and can be removed. Signed-off-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com> Signed-off-by: Zhi Yong Wu <wuzhy@linux.vnet.ibm.com> Reviewed-by: Laszlo Ersek <lersek@redhat.com>
2012-06-27qdev: fix use-after-free in the error path of qdev_init_nofailAnthony Liguori1-2/+3
From Markus: Before: $ qemu-system-x86_64 -display none -drive if=ide qemu-system-x86_64: Device needs media, but drive is empty qemu-system-x86_64: Initialization of device ide-hd failed [Exit 1 ] After: $ qemu-system-x86_64 -display none -drive if=ide qemu-system-x86_64: Device needs media, but drive is empty Segmentation fault (core dumped) [Exit 139 (SIGSEGV)] This error always existed as qdev_init() frees the object. But QOM goes a bit further and purposefully sets the class pointer to NULL to help find use-after-free. It worked :-) Cc: Andreas Faerber <afaerber@suse.de> Reported-by: Markus Armbruster <armbru@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-06-18Merge remote-tracking branch 'afaerber-or/qom-next-2' into stagingAnthony Liguori1-101/+199
* afaerber-or/qom-next-2: (22 commits) qom: Push error reporting to object_property_find() qdev: Remove qdev_prop_exists() qbus: Initialize in standard way qbus: Make child devices links qdev: Connect busses with their parent devices qdev: Convert busses to QEMU Object Model qdev: Move SysBus initialization to sysbus.c qdev: Use wrapper for qdev_get_path qdev: Remove qdev_prop_set_defaults qdev: Clean up global properties qdev: Move bus properties to abstract superclasses qdev: Move bus properties to a separate global qdev: Push "type" property up to Object arm_l2x0: Rename "type" property to "cache-type" m48t59: Rename "type" property to "model" qom: Assert that public types have a non-NULL parent field qom: Drop type_register_static_alias() macro qom: Make Object a type qom: Add class_base_init qom: Add object_child_foreach() ...
2012-06-18qom: Push error reporting to object_property_find()Paolo Bonzini1-1/+1
Avoids duplicated error_set(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [AF: Also drop error_set() in object_property_del().] Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Remove qdev_prop_exists()Paolo Bonzini1-1/+1
Can be replaced everywhere with object_property_find(). Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qbus: Initialize in standard wayAnthony Liguori1-32/+48
Move code to an initfn and finalizer. Replace do_qbus_create_inplace() with qbus_realize(). Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qbus: Make child devices linksAnthony Liguori1-11/+53
Make qbus children show up as link<> properties. There is no stable addressing for qbus children so we use an unstable naming convention. This is okay in QOM though because the composition name is expected to be what's stable. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Connect busses with their parent devicesAnthony Liguori1-0/+4
This makes SysBus part of the root hierarchy and all busses children of their respective parent DeviceState. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Convert busses to QEMU Object ModelAnthony Liguori1-20/+53
This is far less interesting than it sounds. We simply add an Object to each BusState and then register the types appropriately. Most of the interesting refactoring will follow in the next patches. Since we're changing fundamental type names (BusInfo -> BusClass), it all needs to convert at once. Fortunately, not a lot of code is affected. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [AF: Made all new bus TypeInfos static const.] [AF: Made qbus_free() call object_delete(), required {qom,glib}_allocated] Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Move SysBus initialization to sysbus.cPaolo Bonzini1-24/+2
TYPE_SYSTEM_BUS will be local to hw/sysbus.c, so move existing references to main_system_bus and system_bus_info there. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Use wrapper for qdev_get_pathAnthony Liguori1-0/+16
This makes it easier to remove it from BusInfo. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> [AF: Drop now unnecessary NULL initialization in scsibus_get_dev_path()] Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Remove qdev_prop_set_defaultsPaolo Bonzini1-3/+23
Instead, qdev_property_add_static can set the default. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Clean up global propertiesPaolo Bonzini1-1/+1
Now that global properties do not depend on buses anymore, set them directly in the device instance_init function. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Move bus properties to abstract superclassesPaolo Bonzini1-26/+21
In qdev, each bus in practice identified an abstract superclass, but this was mostly hidden. In QOM, instead, these abstract classes are explicit so we can move bus properties there. All bus property walks are removed, and all device property walks are changed to look along the class hierarchy instead. We would have duplicates if class A defines some properties and its subclass B does not define any, because class_b->props will be left equal to class_a->props. The solution here is to reintroduce the class_base_init TypeInfo callback, that was present in one of the early QOM versions but removed (on my request...) before committing. This breaks global bus properties, an obscure feature when used with the command-line which is actually useful and used when used by backwards-compatible machine types. So this patch also adjusts the global bus properties in hw/pc_piix.c to refer to the abstract class. Globals and other properties must be modified in the same patch to avoid complications related to initialization ordering. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-18qdev: Push "type" property up to ObjectPaolo Bonzini1-6/+0
Now that Object is a type, add an instance_init function and push the "type" property from qdev to there. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-06-11qdev: release parent properties on dc->init failureJason Baron1-0/+1
While looking into hot-plugging bridges, I can create a qemu segfault via: $ device_add pci-bridge Bridge chassis not specified. Each bridge is required to be assigned a unique chassis id > 0. ** ERROR:qom/object.c:389:object_delete: assertion failed: (obj->ref == 0) I'm proposing to fix this by adding a call to 'object_unparent()', before the call to qdev_free(). I see there is already a precedent for this usage pattern as seen in qdev_simple_unplug_cb(): /* can be used as ->unplug() callback for the simple cases */ int qdev_simple_unplug_cb(DeviceState *dev) { /* just zap it */ object_unparent(OBJECT(dev)); qdev_free(dev); return 0; } Signed-off-by: Jason Baron <jbaron@redhat.com> Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2012-05-12qdev: Fix adding of ptr propertiesAnthony Liguori1-1/+4
ptr properties have neither a get/set or a print/parse which means that when they're added they aren't treated as static or legacy properties. Just assume properties like this are legacy properties and treat them as such. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Andreas Färber <afaerber@suse.de>
2012-04-24qom: Refine container_get() to allow using a custom rootAndreas Färber1-3/+4
Specify the root to search from as argument. This avoids hardcoding "/machine" in some places and makes it more flexible. Signed-off-by: Andreas Färber <afaerber@suse.de> Cc: Paolo Bonzini <pbonzini@redhat.com> Cc: Anthony Liguori <anthony@codemonkey.ws> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-04-09qdev: qdev_unplug(): use error_set()Luiz Capitulino1-4/+8
It currently uses qerror_report(), but next commit will convert the drive_del command to the QAPI and this requires using error_set(). One particularity of qerror_report() is that it knows when it's running on monitor context or command-line context and prints the error message accordingly. error_set() doesn't do this, so we have to be careful not to drop error messages. qdev_unplug() has three kinds of usages: 1. It's called when hot adding a device fails, to undo anything that has been done before hitting the error 2. It's called by function monitor functions like device_del(), to unplug a device 3. It's used by xen_platform.c in a way that doesn't _seem_ to be in monitor context Only item 2 can print an error message to the user, this commit maintains that. Signed-off-by: Luiz Capitulino <lcapitulino@redhat.com> Reviewed-by: Stefan Hajnoczi <stefanha@linux.vnet.ibm.com>
2012-04-02qdev: put all devices under /machinePaolo Bonzini1-1/+12
Avoid cluttering too much the QOM root. Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-04-02qdev: give all devices a canonical pathPaolo Bonzini1-3/+13
A strong limitation of QOM right now is that unconverted ports (e.g. all...) do not give a canonical path to devices that are part of the board. This in turn makes it impossible to replace PROP_PTR with a QOM link for example. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-17qdev: Fix qdev_try_create() semanticsAndreas Färber1-0/+3
Since QOM'ification, qdev_try_create() uses object_new() internally, which asserts "type != NULL" when the type is not registered. This was revealed by the combination of kvmclock's kvm_enabled() check and early QOM type registration. Check whether the class exists before calling object_new(), so that the caller (e.g., qdev_create) can fail gracefully, telling us which device could not be created. Signed-off-by: Andreas Färber <afaerber@suse.de> Cc: Anthony Liguori <aliguori@codemonkey.ws> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-15qom: Unify type registrationAndreas Färber1-2/+2
Replace device_init() with generalized type_init(). While at it, unify naming convention: type_init([$prefix_]register_types) Also, type_init() is a function, so add preceding blank line where necessary and don't put a semicolon after the closing brace. Signed-off-by: Andreas Färber <afaerber@suse.de> Cc: Anthony Liguori <anthony@codemonkey.ws> Cc: malc <av1474@comtv.ru> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-07qdev: initialize properties via QOMPaolo Bonzini1-2/+2
Similarly, use the object properties also to set the default values of the qdev properties. This requires reordering registration and initialization. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: let QOM free propertiesPaolo Bonzini1-7/+1
Drop the special free callback. Instead, register a "regular" release method in the non-legacy property. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: allow reusing get/set for legacy propertyPaolo Bonzini1-4/+7
In some cases, a legacy property does need a special print method but not a special parse method. In this case, we can reuse the get/set from the static (non-legacy) property. If neither parse nor print is needed, though, do not register the legacy property at all. The previous patch ensures that the right fallback will be used. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-07qdev: remove direct calls to print/parsePaolo Bonzini1-0/+9
There's no need to call into ->parse and ->print manually. The QOM legacy properties do that for us. Furthermore, in some cases legacy and static properties have exactly the same behavior, and we could drop the legacy properties right away. Add an appropriate fallback to prepare for this. Reviewed-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2012-02-03qdev: implement cleanup logic in finalizeAnthony Liguori1-25/+32
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qom: move properties from qdev to objectAnthony Liguori1-474/+17
This is mostly code movement although not entirely. This makes properties part of the Object base class which means that we can now start using Object in a meaningful way outside of qdev. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: nuke qdev_init_chardev()Anthony Liguori1-9/+0
I'm sure the intentions were good here, but there's no reason this should be in qdev. Move it to qemu-char where it belongs. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: split out UI portions into a new functionAnthony Liguori1-571/+1
qdev-monitor.c deals with the -device, device_add, and info qdm/qtree interfaces. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: refactor away qdev_create_from_infoAnthony Liguori1-13/+22
Note that the FIXME gets fixed in series 4/4. We need to convert BusState to QOM before we can make parent_bus a link. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: split out common init to instance_initAnthony Liguori1-13/+28
This gets us closer to being able to object_new() a qdev type and have a functioning object verses having to call qdev_create(). Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: remove baked in notion of aliases (v2)Anthony Liguori1-6/+87
Limit them to the device_add functionality. Device aliases were a hack based on the fact that virtio was modeled the wrong way. The mechanism for aliasing is very limited in that only one alias can exist for any device. We have to support it for the purposes of compatibility but we only need to support it in device_add so restrict it to that piece of code. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com> --- v1 -> v2 - Use a table for aliases (Paolo)
2012-02-03qdev: kill off DeviceInfoAnthony Liguori1-69/+1
It is no longer used in the tree since everything is done natively through QEMU Object Model. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: kill off DeviceInfo listAnthony Liguori1-57/+30
Teach the various bits of code that need to walk through available devices to do so via QOM. Signed-off-by: Anthony Liguori
2012-02-03qdev: refactor device creation to allow bus_info to be set only in classAnthony Liguori1-23/+19
As we use class_init to set class members, DeviceInfo no longer holds this information. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: allow classes to overload qdev functionsAnthony Liguori1-20/+33
This allows us to drop per-Device registration functions by allowing the class_init functions to overload qdev methods. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: remove info from classAnthony Liguori1-38/+56
Now DeviceInfo is no longer used after object construction. All of the relevant members have been moved to DeviceClass. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-02-03qdev: make DeviceInfo privateAnthony Liguori1-1/+29
Introduce accessors and remove any code that directly accesses DeviceInfo members. Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>