pckbd: add QEMU interface comment for I8042_MMIO device
[qemu/armbru.git] / hw / core / qdev-hotplug.c
blobd495d0e9c70a9e080cd3f307f577b852135cf411
1 /*
2 * QDev Hotplug handlers
4 * Copyright (c) Red Hat
6 * SPDX-License-Identifier: GPL-2.0-or-later
8 * This work is licensed under the terms of the GNU GPL, version 2 or later.
9 * See the COPYING file in the top-level directory.
12 #include "qemu/osdep.h"
13 #include "hw/qdev-core.h"
14 #include "hw/boards.h"
16 HotplugHandler *qdev_get_machine_hotplug_handler(DeviceState *dev)
18 MachineState *machine;
19 MachineClass *mc;
20 Object *m_obj = qdev_get_machine();
22 if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {
23 machine = MACHINE(m_obj);
24 mc = MACHINE_GET_CLASS(machine);
25 if (mc->get_hotplug_handler) {
26 return mc->get_hotplug_handler(machine, dev);
30 return NULL;
33 bool qdev_hotplug_allowed(DeviceState *dev, Error **errp)
35 MachineState *machine;
36 MachineClass *mc;
37 Object *m_obj = qdev_get_machine();
39 if (object_dynamic_cast(m_obj, TYPE_MACHINE)) {
40 machine = MACHINE(m_obj);
41 mc = MACHINE_GET_CLASS(machine);
42 if (mc->hotplug_allowed) {
43 return mc->hotplug_allowed(machine, dev, errp);
47 return true;
50 HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev)
52 if (dev->parent_bus) {
53 return dev->parent_bus->hotplug_handler;
55 return NULL;
58 HotplugHandler *qdev_get_hotplug_handler(DeviceState *dev)
60 HotplugHandler *hotplug_ctrl = qdev_get_machine_hotplug_handler(dev);
62 if (hotplug_ctrl == NULL && dev->parent_bus) {
63 hotplug_ctrl = qdev_get_bus_hotplug_handler(dev);
65 return hotplug_ctrl;
68 /* can be used as ->unplug() callback for the simple cases */
69 void qdev_simple_device_unplug_cb(HotplugHandler *hotplug_dev,
70 DeviceState *dev, Error **errp)
72 qdev_unrealize(dev);