diff mbox

[v3] ARM: Exynos4210 IRQ: Introduce new IRQ gate functionality.

Message ID 1334641284-13813-2-git-send-email-e.voevodin@samsung.com
State New
Headers show

Commit Message

Evgeny Voevodin April 17, 2012, 5:41 a.m. UTC
New IRQ gate consists of n_in input qdev gpio lines and one
output sysbus IRQ line. The output IRQ level is formed as OR
between all gpio inputs.

Signed-off-by: Evgeny Voevodin <e.voevodin@samsung.com>
---
 hw/exynos4210.c     |   32 +++++++++++---------
 hw/exynos4210.h     |    2 +-
 hw/exynos4210_gic.c |   79 ++++++++++++++++++++++++++-------------------------
 3 files changed, 58 insertions(+), 55 deletions(-)

Comments

Peter Maydell April 20, 2012, 11:13 a.m. UTC | #1
On 17 April 2012 06:41, Evgeny Voevodin <e.voevodin@samsung.com> wrote:
> +static Property exynos4210_irq_gate_properties[] = {
> +    DEFINE_PROP_UINT32("n_in", Exynos4210IRQGateState, n_in, 1),
> +    DEFINE_PROP_END_OF_LIST(),
> +};
> +
>  static const VMStateDescription vmstate_exynos4210_irq_gate = {
>     .name = "exynos4210.irq_gate",
> -    .version_id = 1,
> -    .minimum_version_id = 1,
> -    .minimum_version_id_old = 1,
> +    .version_id = 2,
> +    .minimum_version_id = 2,
> +    .minimum_version_id_old = 2,
>     .fields = (VMStateField[]) {
> -        VMSTATE_UINT32_ARRAY(gpio_level, Exynos4210IRQGateState,
> -                EXYNOS4210_IRQ_GATE_NINPUTS),
> +        VMSTATE_UINT32(n_in, Exynos4210IRQGateState),
> +        VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, 0, n_in),
>         VMSTATE_END_OF_LIST()

n_in is constant, so you shouldn't need to save/restore it, right?

Otherwise looks good.

PS: 3 days is a bit eager to be sending pings :-) I'd suggest about
a week as the usual time to leave...

-- PMM
Evgeny Voevodin April 20, 2012, 11:51 a.m. UTC | #2
On 20.04.2012 15:13, Peter Maydell wrote:
> On 17 April 2012 06:41, Evgeny Voevodin<e.voevodin@samsung.com>  wrote:
>> +static Property exynos4210_irq_gate_properties[] = {
>> +    DEFINE_PROP_UINT32("n_in", Exynos4210IRQGateState, n_in, 1),
>> +    DEFINE_PROP_END_OF_LIST(),
>> +};
>> +
>>   static const VMStateDescription vmstate_exynos4210_irq_gate = {
>>      .name = "exynos4210.irq_gate",
>> -    .version_id = 1,
>> -    .minimum_version_id = 1,
>> -    .minimum_version_id_old = 1,
>> +    .version_id = 2,
>> +    .minimum_version_id = 2,
>> +    .minimum_version_id_old = 2,
>>      .fields = (VMStateField[]) {
>> -        VMSTATE_UINT32_ARRAY(gpio_level, Exynos4210IRQGateState,
>> -                EXYNOS4210_IRQ_GATE_NINPUTS),
>> +        VMSTATE_UINT32(n_in, Exynos4210IRQGateState),
>> +        VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, 0, n_in),
>>          VMSTATE_END_OF_LIST()
> n_in is constant, so you shouldn't need to save/restore it, right?

Oh, seems so. It's not changing during run-time.

> Otherwise looks good.
>
> PS: 3 days is a bit eager to be sending pings :-) I'd suggest about
> a week as the usual time to leave...

Ok, sorry :)

> -- PMM
>
Evgeny Voevodin April 23, 2012, 5:08 a.m. UTC | #3
On 20.04.2012 15:51, Evgeny Voevodin wrote:
> On 20.04.2012 15:13, Peter Maydell wrote:
>> On 17 April 2012 06:41, Evgeny Voevodin<e.voevodin@samsung.com> wrote:
>>> +static Property exynos4210_irq_gate_properties[] = {
>>> + DEFINE_PROP_UINT32("n_in", Exynos4210IRQGateState, n_in, 1),
>>> + DEFINE_PROP_END_OF_LIST(),
>>> +};
>>> +
>>> static const VMStateDescription vmstate_exynos4210_irq_gate = {
>>> .name = "exynos4210.irq_gate",
>>> - .version_id = 1,
>>> - .minimum_version_id = 1,
>>> - .minimum_version_id_old = 1,
>>> + .version_id = 2,
>>> + .minimum_version_id = 2,
>>> + .minimum_version_id_old = 2,
>>> .fields = (VMStateField[]) {
>>> - VMSTATE_UINT32_ARRAY(gpio_level, Exynos4210IRQGateState,
>>> - EXYNOS4210_IRQ_GATE_NINPUTS),
>>> + VMSTATE_UINT32(n_in, Exynos4210IRQGateState),
>>> + VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, 0,
>>> n_in),
>>> VMSTATE_END_OF_LIST()
>> n_in is constant, so you shouldn't need to save/restore it, right?
>
> Oh, seems so. It's not changing during run-time.
>

Peter, wait, n_in is a property that board sets. So it should be 
saved/restored.

>> Otherwise looks good.
>>
>> PS: 3 days is a bit eager to be sending pings :-) I'd suggest about
>> a week as the usual time to leave...
>
> Ok, sorry :)
>
>> -- PMM
>>
>
>
Peter Maydell April 23, 2012, 7:25 a.m. UTC | #4
On 23 April 2012 06:08, Evgeny Voevodin <e.voevodin@samsung.com> wrote:
> Peter, wait, n_in is a property that board sets. So it should be
> saved/restored.

As I understand it, migration will always be between two identical
configurations. So properties never need to be saved or restored.

-- PMM
diff mbox

Patch

diff --git a/hw/exynos4210.c b/hw/exynos4210.c
index afc4bdc..e2106d6 100644
--- a/hw/exynos4210.c
+++ b/hw/exynos4210.c
@@ -97,11 +97,11 @@  void exynos4210_write_secondary(CPUARMState *env,
 Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
         unsigned long ram_size)
 {
-    qemu_irq cpu_irq[4];
-    int n;
+    qemu_irq cpu_irq[EXYNOS4210_NCPUS];
+    int i, n;
     Exynos4210State *s = g_new(Exynos4210State, 1);
     qemu_irq *irqp;
-    qemu_irq gate_irq[EXYNOS4210_IRQ_GATE_NINPUTS];
+    qemu_irq gate_irq[EXYNOS4210_NCPUS][EXYNOS4210_IRQ_GATE_NINPUTS];
     unsigned long mem_size;
     DeviceState *dev;
     SysBusDevice *busdev;
@@ -127,16 +127,18 @@  Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
     s->irq_table = exynos4210_init_irq(&s->irqs);
 
     /* IRQ Gate */
-    dev = qdev_create(NULL, "exynos4210.irq_gate");
-    qdev_init_nofail(dev);
-    /* Get IRQ Gate input in gate_irq */
-    for (n = 0; n < EXYNOS4210_IRQ_GATE_NINPUTS; n++) {
-        gate_irq[n] = qdev_get_gpio_in(dev, n);
-    }
-    busdev = sysbus_from_qdev(dev);
-    /* Connect IRQ Gate output to cpu_irq */
-    for (n = 0; n < EXYNOS4210_NCPUS; n++) {
-        sysbus_connect_irq(busdev, n, cpu_irq[n]);
+    for (i = 0; i < EXYNOS4210_NCPUS; i++) {
+        dev = qdev_create(NULL, "exynos4210.irq_gate");
+        qdev_prop_set_uint32(dev, "n_in", EXYNOS4210_IRQ_GATE_NINPUTS);
+        qdev_init_nofail(dev);
+        /* Get IRQ Gate input in gate_irq */
+        for (n = 0; n < EXYNOS4210_IRQ_GATE_NINPUTS; n++) {
+            gate_irq[i][n] = qdev_get_gpio_in(dev, n);
+        }
+        busdev = sysbus_from_qdev(dev);
+
+        /* Connect IRQ Gate output to cpu_irq */
+        sysbus_connect_irq(busdev, 0, cpu_irq[i]);
     }
 
     /* Private memory region and Internal GIC */
@@ -146,7 +148,7 @@  Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
     busdev = sysbus_from_qdev(dev);
     sysbus_mmio_map(busdev, 0, EXYNOS4210_SMP_PRIVATE_BASE_ADDR);
     for (n = 0; n < EXYNOS4210_NCPUS; n++) {
-        sysbus_connect_irq(busdev, n, gate_irq[n * 2]);
+        sysbus_connect_irq(busdev, n, gate_irq[n][0]);
     }
     for (n = 0; n < EXYNOS4210_INT_GIC_NIRQ; n++) {
         s->irqs.int_gic_irq[n] = qdev_get_gpio_in(dev, n);
@@ -165,7 +167,7 @@  Exynos4210State *exynos4210_init(MemoryRegion *system_mem,
     /* Map Distributer interface */
     sysbus_mmio_map(busdev, 1, EXYNOS4210_EXT_GIC_DIST_BASE_ADDR);
     for (n = 0; n < EXYNOS4210_NCPUS; n++) {
-        sysbus_connect_irq(busdev, n, gate_irq[n * 2 + 1]);
+        sysbus_connect_irq(busdev, n, gate_irq[n][1]);
     }
     for (n = 0; n < EXYNOS4210_EXT_GIC_NIRQ; n++) {
         s->irqs.ext_gic_irq[n] = qdev_get_gpio_in(dev, n);
diff --git a/hw/exynos4210.h b/hw/exynos4210.h
index f7c7027..1fa47fd 100644
--- a/hw/exynos4210.h
+++ b/hw/exynos4210.h
@@ -56,7 +56,7 @@ 
 /*
  * exynos4210 IRQ subsystem stub definitions.
  */
-#define EXYNOS4210_IRQ_GATE_NINPUTS 8
+#define EXYNOS4210_IRQ_GATE_NINPUTS 2 /* Internal and External GIC */
 
 #define EXYNOS4210_MAX_INT_COMBINER_OUT_IRQ  64
 #define EXYNOS4210_MAX_EXT_COMBINER_OUT_IRQ  16
diff --git a/hw/exynos4210_gic.c b/hw/exynos4210_gic.c
index e1b215e..d930420 100644
--- a/hw/exynos4210_gic.c
+++ b/hw/exynos4210_gic.c
@@ -362,61 +362,65 @@  static void exynos4210_gic_register_types(void)
 
 type_init(exynos4210_gic_register_types)
 
-/*
- * IRQGate struct.
- * IRQ Gate represents OR gate between GICs to pass IRQ to PIC.
+/* IRQ OR Gate struct.
+ *
+ * This device models an OR gate. There are n_in input qdev gpio lines and one
+ * output sysbus IRQ line. The output IRQ level is formed as OR between all
+ * gpio inputs.
  */
 typedef struct {
     SysBusDevice busdev;
 
-    qemu_irq pic_irq[EXYNOS4210_NCPUS]; /* output IRQs to PICs */
-    uint32_t gpio_level[EXYNOS4210_IRQ_GATE_NINPUTS]; /* Input levels */
+    uint32_t n_in;      /* inputs amount */
+    uint32_t *level;    /* input levels */
+    qemu_irq out;       /* output IRQ */
 } Exynos4210IRQGateState;
 
+static Property exynos4210_irq_gate_properties[] = {
+    DEFINE_PROP_UINT32("n_in", Exynos4210IRQGateState, n_in, 1),
+    DEFINE_PROP_END_OF_LIST(),
+};
+
 static const VMStateDescription vmstate_exynos4210_irq_gate = {
     .name = "exynos4210.irq_gate",
-    .version_id = 1,
-    .minimum_version_id = 1,
-    .minimum_version_id_old = 1,
+    .version_id = 2,
+    .minimum_version_id = 2,
+    .minimum_version_id_old = 2,
     .fields = (VMStateField[]) {
-        VMSTATE_UINT32_ARRAY(gpio_level, Exynos4210IRQGateState,
-                EXYNOS4210_IRQ_GATE_NINPUTS),
+        VMSTATE_UINT32(n_in, Exynos4210IRQGateState),
+        VMSTATE_VBUFFER_UINT32(level, Exynos4210IRQGateState, 1, NULL, 0, n_in),
         VMSTATE_END_OF_LIST()
     }
 };
 
-/* Process a change in an external IRQ input.  */
+/* Process a change in IRQ input. */
 static void exynos4210_irq_gate_handler(void *opaque, int irq, int level)
 {
-    Exynos4210IRQGateState *s =
-            (Exynos4210IRQGateState *)opaque;
-    uint32_t odd, even;
-
-    if (irq & 1) {
-        odd = irq;
-        even = irq & ~1;
-    } else {
-        even = irq;
-        odd = irq | 1;
-    }
+    Exynos4210IRQGateState *s = (Exynos4210IRQGateState *)opaque;
+    uint32_t i;
 
-    assert(irq < EXYNOS4210_IRQ_GATE_NINPUTS);
-    s->gpio_level[irq] = level;
+    assert(irq < s->n_in);
 
-    if (s->gpio_level[odd] >= 1 || s->gpio_level[even] >= 1) {
-        qemu_irq_raise(s->pic_irq[even >> 1]);
-    } else {
-        qemu_irq_lower(s->pic_irq[even >> 1]);
+    s->level[irq] = level;
+
+    for (i = 0; i < s->n_in; i++) {
+        if (s->level[i] >= 1) {
+            qemu_irq_raise(s->out);
+            return;
+        }
     }
 
+    qemu_irq_lower(s->out);
+
     return;
 }
 
 static void exynos4210_irq_gate_reset(DeviceState *d)
 {
-    Exynos4210IRQGateState *s = (Exynos4210IRQGateState *)d;
+    Exynos4210IRQGateState *s =
+            DO_UPCAST(Exynos4210IRQGateState, busdev.qdev, d);
 
-    memset(&s->gpio_level, 0, sizeof(s->gpio_level));
+    memset(s->level, 0, s->n_in * sizeof(*s->level));
 }
 
 /*
@@ -424,19 +428,15 @@  static void exynos4210_irq_gate_reset(DeviceState *d)
  */
 static int exynos4210_irq_gate_init(SysBusDevice *dev)
 {
-    unsigned int i;
-    Exynos4210IRQGateState *s =
-            FROM_SYSBUS(Exynos4210IRQGateState, dev);
+    Exynos4210IRQGateState *s = FROM_SYSBUS(Exynos4210IRQGateState, dev);
 
     /* Allocate general purpose input signals and connect a handler to each of
      * them */
-    qdev_init_gpio_in(&s->busdev.qdev, exynos4210_irq_gate_handler,
-            EXYNOS4210_IRQ_GATE_NINPUTS);
+    qdev_init_gpio_in(&s->busdev.qdev, exynos4210_irq_gate_handler, s->n_in);
 
-    /* Connect SysBusDev irqs to device specific irqs */
-    for (i = 0; i < EXYNOS4210_NCPUS; i++) {
-        sysbus_init_irq(dev, &s->pic_irq[i]);
-    }
+    s->level = g_malloc0(s->n_in * sizeof(*s->level));
+
+    sysbus_init_irq(dev, &s->out);
 
     return 0;
 }
@@ -449,6 +449,7 @@  static void exynos4210_irq_gate_class_init(ObjectClass *klass, void *data)
     k->init = exynos4210_irq_gate_init;
     dc->reset = exynos4210_irq_gate_reset;
     dc->vmsd = &vmstate_exynos4210_irq_gate;
+    dc->props = exynos4210_irq_gate_properties;
 }
 
 static TypeInfo exynos4210_irq_gate_info = {