All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
To: qemu-devel@nongnu.org, edgar.iglesias@gmail.com,
	blauwirbel@gmail.com, aliguori@us.ibm.com
Cc: peter.crosthwaite@petalogix.com
Subject: [Qemu-devel] [PATCH 04/14] qdev: allow multiple qdev_init_gpio_in() calls
Date: Fri,  5 Oct 2012 10:08:49 +1000	[thread overview]
Message-ID: <1349395739-26502-5-git-send-email-peter.crosthwaite@xilinx.com> (raw)
In-Reply-To: <1349395739-26502-1-git-send-email-peter.crosthwaite@xilinx.com>

From: Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com>

Allow multiple qdev_init_gpio_in() calls for the one device. The first call will
define GPIOs 0-N-1, the next GPIOs N- ... . Allows different GPIOs to be handled
with different handlers. Needed when two levels of the QOM class heirachy both
define GPIO functionality, as a single GPIO handler with an index selecter is
not possible.

Signed-off-by: Peter A. G. Crosthwaite <peter.crosthwaite@petalogix.com>
---
 hw/irq.c  |   27 ++++++++++++++++++++-------
 hw/irq.h  |   11 ++++++++++-
 hw/qdev.c |    6 +++---
 3 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/hw/irq.c b/hw/irq.c
index d413a0b..f4e2a78 100644
--- a/hw/irq.c
+++ b/hw/irq.c
@@ -38,24 +38,37 @@ void qemu_set_irq(qemu_irq irq, int level)
     irq->handler(irq->opaque, irq->n, level);
 }
 
-qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
+qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
+                           void *opaque, int n)
 {
     qemu_irq *s;
     struct IRQState *p;
     int i;
 
-    s = (qemu_irq *)g_malloc0(sizeof(qemu_irq) * n);
-    p = (struct IRQState *)g_malloc0(sizeof(struct IRQState) * n);
-    for (i = 0; i < n; i++) {
-        p->handler = handler;
-        p->opaque = opaque;
-        p->n = i;
+    if (!old) {
+        n_old = 0;
+    }
+    s = old ? g_renew(qemu_irq, old, n + n_old) : g_new(qemu_irq, n);
+    p = old ? g_renew(struct IRQState, s[0], n + n_old) :
+                g_new(struct IRQState, n);
+    for (i = 0; i < n + n_old; i++) {
+        if (i >= n_old) {
+            p->handler = handler;
+            p->opaque = opaque;
+            p->n = i;
+        }
         s[i] = p;
         p++;
     }
     return s;
 }
 
+qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n)
+{
+    return qemu_extend_irqs(NULL, 0, handler, opaque, n);
+}
+
+
 void qemu_free_irqs(qemu_irq *s)
 {
     g_free(s[0]);
diff --git a/hw/irq.h b/hw/irq.h
index 56c55f0..e640c10 100644
--- a/hw/irq.h
+++ b/hw/irq.h
@@ -23,8 +23,17 @@ static inline void qemu_irq_pulse(qemu_irq irq)
     qemu_set_irq(irq, 0);
 }
 
-/* Returns an array of N IRQs.  */
+/* Returns an array of N IRQs. Each IRQ is assigned the argument handler and
+ * opaque data.
+ */
 qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n);
+
+/* Extends an Array of IRQs. Old IRQs have their handlers and opaque data
+ * preserved. New IRQs are assigned the argument handler and opaque data.
+ */
+qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler,
+                                void *opaque, int n);
+
 void qemu_free_irqs(qemu_irq *s);
 
 /* Returns a new IRQ with opposite polarity.  */
diff --git a/hw/qdev.c b/hw/qdev.c
index b5a52ac..eea9eae 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -291,9 +291,9 @@ BusState *qdev_get_parent_bus(DeviceState *dev)
 
 void qdev_init_gpio_in(DeviceState *dev, qemu_irq_handler handler, int n)
 {
-    assert(dev->num_gpio_in == 0);
-    dev->num_gpio_in = n;
-    dev->gpio_in = qemu_allocate_irqs(handler, dev, n);
+    dev->gpio_in = qemu_extend_irqs(dev->gpio_in, dev->num_gpio_in, handler,
+                                        dev, n);
+    dev->num_gpio_in += n;
 }
 
 void qdev_init_gpio_out(DeviceState *dev, qemu_irq *pins, int n)
-- 
1.7.0.4

  parent reply	other threads:[~2012-10-05  0:09 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-05  0:08 [Qemu-devel] [PULL 0/14] Ehnahced SSI bus support + M25P80 SPI flash + Xilinx SPI controller Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 01/14] ssi: Support for multiple attached devices Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 02/14] ssi: Implemented CS behaviour Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 03/14] ssi: Added create_slave_no_init() Peter Crosthwaite
2012-10-05  0:08 ` Peter Crosthwaite [this message]
2012-10-05  8:50   ` [Qemu-devel] [PATCH 04/14] qdev: allow multiple qdev_init_gpio_in() calls Peter Maydell
2012-10-05  0:08 ` [Qemu-devel] [PATCH 05/14] hw/stellaris: Removed gpio_out init array Peter Crosthwaite
2012-10-05 12:31   ` Peter Maydell
2012-10-05 14:17     ` Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 06/14] stellaris: Removed SSI mux Peter Crosthwaite
2012-10-05 12:34   ` Peter Maydell
2012-10-05 14:14     ` Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 07/14] hw: Added generic FIFO API Peter Crosthwaite
2012-10-05 12:45   ` Peter Maydell
2012-10-05  0:08 ` [Qemu-devel] [PATCH 08/14] m25p80: Initial implementation of SPI flash device Peter Crosthwaite
2012-10-05 12:22   ` Peter Maydell
2012-10-05  0:08 ` [Qemu-devel] [PATCH 09/14] xilinx_spi: Initial impl. of Xilinx SPI controller Peter Crosthwaite
2012-10-05 12:42   ` Peter Maydell
2012-10-05 12:49     ` Peter Crosthwaite
2012-10-05 12:52       ` Peter Maydell
2012-10-05  0:08 ` [Qemu-devel] [PATCH 10/14] petalogix-ml605: added SPI controller with n25q128 Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 11/14] xilinx_spips: Xilinx Zynq SPI cntrlr device model Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 12/14] xilinx_zynq: Added SPI controllers + flashes Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 13/14] MAINTAINERS: Added maintainerships for SSI Peter Crosthwaite
2012-10-05  0:08 ` [Qemu-devel] [PATCH 14/14] ssi: Add slave autoconnect helper Peter Crosthwaite
2012-10-05 12:50 ` [Qemu-devel] [PULL 0/14] Ehnahced SSI bus support + M25P80 SPI flash + Xilinx SPI controller Peter Maydell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1349395739-26502-5-git-send-email-peter.crosthwaite@xilinx.com \
    --to=peter.crosthwaite@petalogix.com \
    --cc=aliguori@us.ibm.com \
    --cc=blauwirbel@gmail.com \
    --cc=edgar.iglesias@gmail.com \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.