aboutsummaryrefslogtreecommitdiff
path: root/hw/core/qdev.c
diff options
context:
space:
mode:
authorPeter Crosthwaite <peter.crosthwaite@xilinx.com>2014-09-25 22:20:58 -0700
committerPaolo Bonzini <pbonzini@redhat.com>2014-10-23 16:41:25 +0200
commit0c24db2b8c60cb578d7af6fb50c0ad60a723a02d (patch)
treef2982421bf6d0b2d395554350cd0ebeeaf6f51d6 /hw/core/qdev.c
parent02757df2ad2d5dfc96482e2cdfa046f439dafc3d (diff)
qdev: gpio: Add API for intercepting a GPIO
To replace the old qemu_irq intercept API (which had users reaching into qdev private state for GPIOs). Reviewed-by: Alexander Graf <agraf@suse.de> Signed-off-by: Peter Crosthwaite <peter.crosthwaite@xilinx.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'hw/core/qdev.c')
-rw-r--r--hw/core/qdev.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/hw/core/qdev.c b/hw/core/qdev.c
index fc7860f0bb..92f88f6698 100644
--- a/hw/core/qdev.c
+++ b/hw/core/qdev.c
@@ -455,6 +455,31 @@ void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
g_free(propname);
}
+/* disconnect a GPIO ouput, returning the disconnected input (if any) */
+
+static qemu_irq qdev_disconnect_gpio_out_named(DeviceState *dev,
+ const char *name, int n)
+{
+ char *propname = g_strdup_printf("%s[%d]",
+ name ? name : "unnamed-gpio-out", n);
+
+ qemu_irq ret = (qemu_irq)object_property_get_link(OBJECT(dev), propname,
+ NULL);
+ if (ret) {
+ object_property_set_link(OBJECT(dev), NULL, propname, NULL);
+ }
+ g_free(propname);
+ return ret;
+}
+
+qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt,
+ const char *name, int n)
+{
+ qemu_irq disconnected = qdev_disconnect_gpio_out_named(dev, name, n);
+ qdev_connect_gpio_out_named(dev, name, n, icpt);
+ return disconnected;
+}
+
void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
{
qdev_connect_gpio_out_named(dev, NULL, n, pin);