Skip to content

Commit

Permalink
qdev: gpio: Add API for intercepting a GPIO
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
pete128 authored and bonzini committed Oct 23, 2014
1 parent 02757df commit 0c24db2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
25 changes: 25 additions & 0 deletions hw/core/qdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions include/hw/qdev-core.h
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,8 @@ qemu_irq qdev_get_gpio_in_named(DeviceState *dev, const char *name, int n);
void qdev_connect_gpio_out(DeviceState *dev, int n, qemu_irq pin);
void qdev_connect_gpio_out_named(DeviceState *dev, const char *name, int n,
qemu_irq pin);
qemu_irq qdev_intercept_gpio_out(DeviceState *dev, qemu_irq icpt,
const char *name, int n);

BusState *qdev_get_child_bus(DeviceState *dev, const char *name);

Expand Down

0 comments on commit 0c24db2

Please sign in to comment.