Received: from eggs.gnu.org ([2001:4830:134:3::10]:45194) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfALH-0003UR-Cw for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:32 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XfALC-0004ds-5H for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:27 -0400 Received: from mail-wi0-x22d.google.com ([2a00:1450:400c:c05::22d]:35480) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XfALB-0004df-Vi for qemu-devel@nongnu.org; Fri, 17 Oct 2014 12:25:22 -0400 Received: by mail-wi0-f173.google.com with SMTP id fb4so2547805wid.6 for ; Fri, 17 Oct 2014 09:25:21 -0700 (PDT) Sender: Paolo Bonzini From: Paolo Bonzini Date: Fri, 17 Oct 2014 18:24:54 +0200 Message-Id: <1413563095-27301-13-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 12/13] qdev: gpio: Define qdev_pass_gpios() 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 Allows a container to take ownership of GPIOs in a contained device and automatically connect them as GPIOs to the container. This prepares for deprecation of the SYSBUS IRQ functionality, which has this feature. We push it up to the device level instead of sysbus level. There's nothing sysbus specific about passing GPIOs to containers so its a legitimate device-level generic feature. Reviewed-by: Alexander Graf Signed-off-by: Peter Crosthwaite Signed-off-by: Paolo Bonzini --- hw/core/qdev.c | 26 ++++++++++++++++++++++++++ include/hw/qdev-core.h | 3 +++ 2 files changed, 29 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index c143cd0..0ff8039 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -446,6 +446,32 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin) qdev_connect_gpio_out_named(dev, NULL, n, pin); } +void qdev_pass_gpios(DeviceState *dev, DeviceState *container, + const char *name) +{ + int i; + NamedGPIOList *ngl = qdev_get_named_gpio_list(dev, name); + + for (i = 0; i < ngl->num_in; i++) { + const char *nm = ngl->name ? ngl->name : "unnamed-gpio-in"; + char *propname = g_strdup_printf("%s[%d]", nm, i); + + object_property_add_alias(OBJECT(container), propname, + OBJECT(dev), propname, + &error_abort); + } + for (i = 0; i < ngl->num_out; i++) { + const char *nm = ngl->name ? ngl->name : "unnamed-gpio-out"; + char *propname = g_strdup_printf("%s[%d]", nm, i); + + object_property_add_alias(OBJECT(container), propname, + OBJECT(dev), propname, + &error_abort); + } + QLIST_REMOVE(ngl, node); + QLIST_INSERT_HEAD(&container->gpios, ngl, node); +} + BusState *qdev_get_child_bus(DeviceState *dev, const char *name) { BusState *bus; diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index eac603b..77b193b 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -289,6 +289,9 @@ void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler, void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, const char *name, int n); +void qdev_pass_gpios(DeviceState *dev, DeviceState *container, + const char *name); + BusState *qdev_get_parent_bus(DeviceState *dev); /*** BUS API. ***/ -- 2.1.0