Received: from eggs.gnu.org ([2001:4830:134:3::10]:45152) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfALB-0003NE-GZ for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:26 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfAL4-0004bz-RR for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:21 -0400 Received: from mail-wi0-x231.google.com ([2a00:1450:400c:c05::231]:42785) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfAL4-0004bl-LA for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:14 -0400 Received: by mail-wi0-f177.google.com with SMTP id fb4so1712490wid.4 for ; Fri, 17 Oct 2014 09:25:13 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 17 Oct 2014 18:24:49 +0200 Message-Id: <1413563095-27301-8-git-send-email-pbonzini@redhat.com> In-Reply-To: <1413563095-27301-1-git-send-email-pbonzini@redhat.com> References: <1413563095-27301-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH qom v4 07/13] qdev: gpio: Add API for intercepting a GPIO List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Peter Crosthwaite , afaerber@suse.de, agraf@suse.de From: Peter Crosthwaite To replace the old qemu_irq intercept API (which had users reaching into qdev private state for GPIOs). Reviewed-by: Alexander Graf Signed-off-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 25 +++++++++++++++++++++++++ include/hw/qdev-core.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 121a40b..2a88768 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -418,6 +418,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); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 178fee2..31301e5 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -274,6 +274,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); -- 2.1.0