From patchwork Fri Mar 2 11:06:16 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 130505 Delivered-To: patch@linaro.org Received: by 10.46.66.2 with SMTP id p2csp1148500lja; Fri, 2 Mar 2018 03:13:28 -0800 (PST) X-Google-Smtp-Source: AG47ELuEU75/g5KyTsD2Ar1sohGByHlPXF4JGi5Ar/9B1MJhHZyPgEhANzIXZ3p4rm1Mj/IkaJSi X-Received: by 2002:a25:d044:: with SMTP id h65-v6mr3301318ybg.44.1519989208554; Fri, 02 Mar 2018 03:13:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519989208; cv=none; d=google.com; s=arc-20160816; b=mA2KMfWzf6JN0Z7twarWlbX7IsR3WtpMG5TnFgy9e8ZmQoeNwaOlh7MmrFgG8jeATq ZdLknYNMJcCowyKK1meFwHAjYKu5P2LK7Tk2UtpMUEwAYnFeH/osqstdIVTlESfL9nLk RMrllq+2AMdUbcjOwJoJJ9r5iJ9LYAJ9FZS+K0b55bchmdQ+iXLfi4ImQ9kRGumgoty4 Zqziw+d0el2hIiCfxvwBWXUein8ABW0wXHC9tc71EREQT/Df6C5ZsI+6G3ywjyPxJTAx gpYEdNqC0HB5Dg94HV8O2IxeQy9Gy12XeUF6t3hPZ0lwR3qOYxegBm+X6BE83n5OCRma T3Wg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:arc-authentication-results; bh=T/LLywK8NKHLnqmpGM3qzhtHaY7NP8db1qP4zfCzk6E=; b=XkMgea9q6gLK96QGjZv+WtourSugn2nXxUlCPsnsCFICjyk39XawzmMSNXy1nZ9jGe oF6hNX/d31iO3DsmopQNLZAz06a1ZMQMpr7X3Wq+I/LL3AhUB/x/xKtyN58lSSe6qCJ6 QKbkCvAK62OaTv24iBSyinJABFDgrO52TVNgJp6j/VXFwPmOQMCM8MMExjRyqbgDvRR2 N0//zLJqu00M1YBmHSdWPmvcbNuPY+HHInGeq4nlYjEQlxPkBygFsuAinU/BmUudaetK Vv06TFREbQlfARdutdW5Nvb5YpT/km8rjj//DKYMRAsM74RuIrZ76k5d5D1aQhwYYOI+ cC+w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id 202si1038157ywy.10.2018.03.02.03.13.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 02 Mar 2018 03:13:28 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:34089 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ericx-0008Vw-TG for patch@linaro.org; Fri, 02 Mar 2018 06:13:27 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43412) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eriWb-0002us-VY for qemu-devel@nongnu.org; Fri, 02 Mar 2018 06:06:55 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eriWa-0004u8-VO for qemu-devel@nongnu.org; Fri, 02 Mar 2018 06:06:53 -0500 Received: from orth.archaic.org.uk ([2001:8b0:1d0::2]:46760) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eriWa-0004tj-N9 for qemu-devel@nongnu.org; Fri, 02 Mar 2018 06:06:52 -0500 Received: from pm215 by orth.archaic.org.uk with local (Exim 4.89) (envelope-from ) id 1eriWZ-0001M4-Pb for qemu-devel@nongnu.org; Fri, 02 Mar 2018 11:06:51 +0000 From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 2 Mar 2018 11:06:16 +0000 Message-Id: <20180302110640.28004-16-peter.maydell@linaro.org> X-Mailer: git-send-email 2.16.2 In-Reply-To: <20180302110640.28004-1-peter.maydell@linaro.org> References: <20180302110640.28004-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2001:8b0:1d0::2 Subject: [Qemu-devel] [PULL 15/39] qdev: Add new qdev_init_gpio_in_named_with_opaque() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The function qdev_init_gpio_in_named() passes the DeviceState pointer as the opaque data pointor for the irq handler function. Usually this is what you want, but in some cases it would be helpful to use some other data pointer. Add a new function qdev_init_gpio_in_named_with_opaque() which allows the caller to specify the data pointer they want. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Reviewed-by: Richard Henderson Message-id: 20180220180325.29818-12-peter.maydell@linaro.org --- include/hw/qdev-core.h | 30 ++++++++++++++++++++++++++++-- hw/core/qdev.c | 8 +++++--- 2 files changed, 33 insertions(+), 5 deletions(-) -- 2.16.2 diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index fc9d617a76..9453588160 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -311,10 +311,36 @@ BusState *qdev_get_child_bus(DeviceState *dev, const char *name); /* GPIO inputs also double as IRQ sinks. */ void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n); void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n); -void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler, - const char *name, int n); void qdev_init_gpio_out_named(DeviceState *dev, qemu_irq *pins, const char *name, int n); +/** + * qdev_init_gpio_in_named_with_opaque: create an array of input GPIO lines + * for the specified device + * + * @dev: Device to create input GPIOs for + * @handler: Function to call when GPIO line value is set + * @opaque: Opaque data pointer to pass to @handler + * @name: Name of the GPIO input (must be unique for this device) + * @n: Number of GPIO lines in this input set + */ +void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, + qemu_irq_handler handler, + void *opaque, + const char *name, int n); + +/** + * qdev_init_gpio_in_named: create an array of input GPIO lines + * for the specified device + * + * Like qdev_init_gpio_in_named_with_opaque(), but the opaque pointer + * passed to the handler is @dev (which is the most commonly desired behaviour). + */ +static inline void qdev_init_gpio_in_named(DeviceState *dev, + qemu_irq_handler handler, + const char *name, int n) +{ + qdev_init_gpio_in_named_with_opaque(dev, handler, dev, name, n); +} void qdev_pass_gpios(DeviceState *dev, DeviceState *container, const char *name); diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 7ed1f431f0..f3754ee606 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -385,15 +385,17 @@ static NamedGPIOList *qdev_get_named_gpio_list(DeviceState *dev, return ngl; } -void qdev_init_gpio_in_named(DeviceState *dev, qemu_irq_handler handler, - const char *name, int n) +void qdev_init_gpio_in_named_with_opaque(DeviceState *dev, + qemu_irq_handler handler, + void *opaque, + const char *name, int n) { int i; NamedGPIOList *gpio_list = qdev_get_named_gpio_list(dev, name); assert(gpio_list->num_out == 0 || !name); gpio_list->in = qemu_extend_irqs(gpio_list->in, gpio_list->num_in, handler, - dev, n); + opaque, n); if (!name) { name = "unnamed-gpio-in";