From patchwork Thu Oct 23 13:33:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 402495 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A19D2140082 for ; Fri, 24 Oct 2014 00:36:05 +1100 (AEDT) Received: from localhost ([::1]:39753 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhIYd-0007qa-EP for incoming@patchwork.ozlabs.org; Thu, 23 Oct 2014 09:36:03 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:54656) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhIXI-0005id-La for qemu-devel@nongnu.org; Thu, 23 Oct 2014 09:34:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XhIXD-0007Lu-CD for qemu-devel@nongnu.org; Thu, 23 Oct 2014 09:34:40 -0400 Received: from mail-wi0-x230.google.com ([2a00:1450:400c:c05::230]:54204) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XhIXD-0007Lk-5V for qemu-devel@nongnu.org; Thu, 23 Oct 2014 09:34:35 -0400 Received: by mail-wi0-f176.google.com with SMTP id n3so3662985wiv.9 for ; Thu, 23 Oct 2014 06:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=xJPO/7eoFkdLNd4gzD+nikvoy5lfrt3bXWL5UQYG70I=; b=AUcarxnHpKjcQNkIFSznRh+EZPHLpbrhddKKjdp/IZ5vwFquVa3N4eiKTnmXh2SplJ INvlQLuNz6luhu18/34k4wiWOPuej/fhkKaKs+vUQsiVXRWyBsFWTAHFjneKTc9G3//B N7dqBFFnIuqyEB2CXKiSNHu0TnYTWUDHh2pqv2njD+CwfQyXV9N+GRsUWYbD8kujV7lH 2Fi39eMz7wdWASLKXX/rnjYYrqa4fZLmbPcpPLj26v8TglSw6D9WrWylhqxk6QigmHkk bEOX8CUfLzsJKK2kQXe8AkQHW/vme9ev4Ml40CBpmhOh5OMfrHIECt+NZVzn0TgFp5WD 9AKw== X-Received: by 10.180.211.226 with SMTP id nf2mr12904048wic.61.1414071274443; Thu, 23 Oct 2014 06:34:34 -0700 (PDT) Received: from playground.station (net-37-117-142-149.cust.vodafonedsl.it. [37.117.142.149]) by mx.google.com with ESMTPSA id u8sm5445638wiz.14.2014.10.23.06.34.32 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 23 Oct 2014 06:34:33 -0700 (PDT) From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Thu, 23 Oct 2014 15:33:56 +0200 Message-Id: <1414071252-7003-9-git-send-email-pbonzini@redhat.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1414071252-7003-1-git-send-email-pbonzini@redhat.com> References: <1414071252-7003-1-git-send-email-pbonzini@redhat.com> X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a00:1450:400c:c05::230 Cc: Peter Crosthwaite Subject: [Qemu-devel] [PULL 08/24] qdev: gpio: Add API for intercepting a GPIO X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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 fc7860f..92f88f6 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); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 1fca75c..cf27e65 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -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);