From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35458) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XH8CX-0001N0-FJ for qemu-devel@nongnu.org; Tue, 12 Aug 2014 05:17:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XH8CR-00036s-7C for qemu-devel@nongnu.org; Tue, 12 Aug 2014 05:17:05 -0400 Received: from cantor2.suse.de ([195.135.220.15]:39529 helo=mx2.suse.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XH8CQ-00036o-W5 for qemu-devel@nongnu.org; Tue, 12 Aug 2014 05:16:59 -0400 Message-ID: <53E9DB89.3080706@suse.de> Date: Tue, 12 Aug 2014 11:16:57 +0200 From: Alexander Graf MIME-Version: 1.0 References: In-Reply-To: Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH v1 08/16] qdev: gpio: Add API for intercepting an IRQ List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Crosthwaite , qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, afaerber@suse.de, pbonzini@redhat.com On 04.08.14 03:55, Peter Crosthwaite wrote: > To replace the old qemu_irq intercept API (which had users reaching > into qdev private state for IRQs). > > Signed-off-by: Peter Crosthwaite > --- > > 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 e6b2231..4cbf773 100644 > --- a/hw/core/qdev.c > +++ b/hw/core/qdev.c > @@ -412,6 +412,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; > +} > + > +void qdev_intercept_gpio_out(DeviceState *dev, qemu_irq_handler handler, > + const char *name, int n) > +{ > + qemu_irq disconnected = qdev_disconnect_gpio_out_named(dev, name, n); > + qemu_irq icpt = qemu_allocate_irq(handler, disconnected, n); This means that we can't pass in any other opaque to the intercepting handler which sounds suboptimal to me. Can't we pass in a qemu_irq as parameter and a pointer to a field where we can store the disconnected qemu_irq? Then the caller can allocate its own qemu_irq with all the opaque data it wants and just have the intercept function overwrite a single field in the passed down opaque. Or you just return the disconnected qemu_irq. Then the caller can do whatever it likes with it, such as set icpt->opaque to it. Alex