Skip to contentSkip to conversation

hw/intc: add sunxi interrupt controller device

PATCH In review liguang 2 participants 4 messages Nov 27, 2013 Arm/Allwinner sunXi SoC support

lore
Share & tools
lore

liguang

author
#0 lore raw

PATCH v5 3/5 hw/intc: add sunxi interrupt controller device

---
 default-configs/arm-softmmu.mak |    1 +
 hw/intc/Makefile.objs           |    1 +
 hw/intc/sunxi-pic.c             |  247 +++++++++++++++++++++++++++++++++++++++
 include/hw/intc/sunxi-pic.h     |   20 +++
 4 files changed, 269 insertions(+), 0 deletions(-)
 create mode 100644 hw/intc/sunxi-pic.c
 create mode 100644 include/hw/intc/sunxi-pic.h
default-configs/arm-softmmu.mak +1 -0
index 7bf5ad0..bbe00e4 100644
@@ -83,3 +83,4 @@ CONFIG_SDHCI=y
 CONFIG_INTEGRATOR_DEBUG=y
 
 CONFIG_SUNXI_PIT=y
+CONFIG_SUNXI_PIC=y
hw/intc/Makefile.objs +1 -0
index 47ac442..dad8c43 100644
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_IOAPIC) += ioapic_common.o
 common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o
 common-obj-$(CONFIG_ARM_GIC) += arm_gic.o
 common-obj-$(CONFIG_OPENPIC) += openpic.o
+common-obj-$(CONFIG_SUNXI_PIC) += sunxi-pic.o
 
 obj-$(CONFIG_APIC) += apic.o apic_common.o
 obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o
hw/intc/sunxi-pic.c new file +247 -0

247 lines not on this page · raw message

include/hw/intc/sunxi-pic.h new file +20 -0
new file mode 100644
index 0000000..b745f1c
@@ -0,0 +1,20 @@
+#ifndef SUNXI_PIC_H
+#define SUNXI_PIC_H
+
+#define TYPE_SUNXI_PIC  "sunxi-pic"
+#define SUNXI_PIC(obj) OBJECT_CHECK(SunxiPICState, (obj), TYPE_SUNXI_PIC)
+
+#define SUNXI_PIC_VECTOR 	0
+#define SUNXI_PIC_BASE_ADDR 	4
+#define SUNXI_PIC_PROTECT 	8
+#define SUNXI_PIC_NMI		0xc
+#define SUNXI_PIC_IRQ_PENDING	0x10
+#define SUNXI_PIC_FIQ_PENDING	0x20
+#define SUNXI_PIC_SELECT	0x30
+#define SUNXI_PIC_ENABLE	0x40
+#define SUNXI_PIC_MASK		0x50
+
+#define SUNXI_PIC_INT_NR	95
+#define SUNXI_PIC_REG_IDX	DIV_ROUND_UP(SUNXI_PIC_INT_NR, 32)
+
+#endif
Signature · 1 line
1.7.2.5
#1 lore raw
Quoted 63 lines · liguang
---
 default-configs/arm-softmmu.mak |    1 +
 hw/intc/Makefile.objs           |    1 +
 hw/intc/sunxi-pic.c             |  247 +++++++++++++++++++++++++++++++++++++++
 include/hw/intc/sunxi-pic.h     |   20 +++
 4 files changed, 269 insertions(+), 0 deletions(-)
 create mode 100644 hw/intc/sunxi-pic.c
 create mode 100644 include/hw/intc/sunxi-pic.h
default-configs/arm-softmmu.mak +1 -0
index 7bf5ad0..bbe00e4 100644
@@ -83,3 +83,4 @@ CONFIG_SDHCI=y
 CONFIG_INTEGRATOR_DEBUG=y
 
 CONFIG_SUNXI_PIT=y
+CONFIG_SUNXI_PIC=y
hw/intc/Makefile.objs +1 -0
index 47ac442..dad8c43 100644
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_IOAPIC) += ioapic_common.o
 common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o
 common-obj-$(CONFIG_ARM_GIC) += arm_gic.o
 common-obj-$(CONFIG_OPENPIC) += openpic.o
+common-obj-$(CONFIG_SUNXI_PIC) += sunxi-pic.o
 
 obj-$(CONFIG_APIC) += apic.o apic_common.o
 obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o
hw/intc/sunxi-pic.c new file +26 -0
new file mode 100644
index 0000000..a588c30
@@ -0,0 +1,247 @@
+/*
+ * Allwinner sunxi interrupt controller device emulation
+ *
+ * Copyright (C) 2013 Li Guang
+ * Written by Li Guang <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "hw/sysbus.h"
+#include "hw/devices.h"
+#include "sysemu/sysemu.h"
+#include "hw/intc/sunxi-pic.h"
+
+
+typedef struct SunxiPICState {
+    /*< private >*/
+    SysBusDevice parent_obj;

hw/intc/sunxi-pic.c line 36

Quoted 10 lines
hw/intc/sunxi-pic.c new file +10 -0
+    /*< public >*/
+    MemoryRegion iomem;
+    qemu_irq parent_fiq;
+    qemu_irq parent_irq;
+
+    uint32_t vector;
+    uint32_t base_addr;
+    uint32_t protect;
+    uint32_t nmi;
+    uint32_t irq_pending[SUNXI_PIC_REG_IDX];

IDX is a wierd choice of suffix here. Is this really a "_NUM". I'm happy as is though.

Quoted 18 lines
hw/intc/sunxi-pic.c new file +18 -0
+    uint32_t fiq_pending[SUNXI_PIC_REG_IDX];
+    uint32_t select[SUNXI_PIC_REG_IDX];
+    uint32_t enable[SUNXI_PIC_REG_IDX];
+    uint32_t mask[SUNXI_PIC_REG_IDX];
+    /*priority setting here*/
+} SunxiPICState;
+
+static void sunxi_pic_update(SunxiPICState *s)
+{
+    uint8_t i, j;
+    bool irq = false, fiq = false;
+
+    for (i = 0, j = 0; i < SUNXI_PIC_REG_IDX; i++) {
+        if (s->irq_pending[i] == 0 && s->fiq_pending[i] == 0) {
+            continue;
+        }
+        for (j = 0; j < 32; j++) {
+            if (test_bit(j, (void *)&s->mask[i])) {

hw/intc/sunxi-pic.c line 64

Quoted 10 lines
hw/intc/sunxi-pic.c new file +10 -0
+                continue;
+            }
+            if (test_bit(j, (void *)&s->irq_pending[i])) {
+                irq = true;
+            }
+            if (test_bit(j, (void *)&s->fiq_pending[i]) &&
+                test_bit(j, (void *)&s->select[i])) {
+                fiq = true;
+            }
+            if (irq || fiq) {

This should be an && - the missed fiq problem i mentioned last time still isnt solved. If an early iteration of this loop sets irq then no latter iterations are given the chance to set fiq. You can only bail out of the loop if both irq and fix are set. You could just ditch this escape logic completely as I doubt its too much of a performance hit.

Quoted 19 lines
hw/intc/sunxi-pic.c new file +19 -0
+                goto out;
+            }
+        }
+    }
+
+out:
+    qemu_set_irq(s->parent_irq, irq);
+    qemu_set_irq(s->parent_fiq, fiq);
+}
+
+static void sunxi_pic_set_irq(void *opaque, int irq, int level)
+{
+    SunxiPICState *s = opaque;
+
+    if (level) {
+        set_bit(irq%32, (void *)&s->irq_pending[irq/32]);
+    }
+    sunxi_pic_update(s);
+}

hw/intc/sunxi-pic.c line 93

Quoted 10 lines
hw/intc/sunxi-pic.c new file +10 -0
+
+static uint64_t sunxi_pic_read(void *opaque, hwaddr offset, unsigned size)
+{
+    SunxiPICState *s = opaque;
+    uint8_t index = (offset & 0xc)/4;
+
+    switch (offset) {
+    case SUNXI_PIC_VECTOR:
+        return s->vector;
+        break;

Breaks after return. Fix globally.

Regards,
Peter

author
#2 lore raw
Quoted 70 lines · Peter Crosthwaite
Quoted 68 lines · liguang
---
  default-configs/arm-softmmu.mak |    1 +
  hw/intc/Makefile.objs           |    1 +
  hw/intc/sunxi-pic.c             |  247 +++++++++++++++++++++++++++++++++++++++
  include/hw/intc/sunxi-pic.h     |   20 +++
  4 files changed, 269 insertions(+), 0 deletions(-)

create mode 100644 hw/intc/sunxi-pic.c
create mode 100644 include/hw/intc/sunxi-pic.h

default-configs/arm-softmmu.mak +1 -0
index 7bf5ad0..bbe00e4 100644
@@ -83,3 +83,4 @@ CONFIG_SDHCI=y
  CONFIG_INTEGRATOR_DEBUG=y
 
  CONFIG_SUNXI_PIT=y
+CONFIG_SUNXI_PIC=y
hw/intc/Makefile.objs +1 -0
index 47ac442..dad8c43 100644
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_IOAPIC) += ioapic_common.o
  common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o
  common-obj-$(CONFIG_ARM_GIC) += arm_gic.o
  common-obj-$(CONFIG_OPENPIC) += openpic.o
+common-obj-$(CONFIG_SUNXI_PIC) += sunxi-pic.o
 
  obj-$(CONFIG_APIC) += apic.o apic_common.o
  obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o
hw/intc/sunxi-pic.c new file +31 -0
new file mode 100644
index 0000000..a588c30
@@ -0,0 +1,247 @@
+/*
+ * Allwinner sunxi interrupt controller device emulation
+ *
+ * Copyright (C) 2013 Li Guang
+ * Written by Li Guang<[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */
+
+#include "hw/sysbus.h"
+#include "hw/devices.h"
+#include "sysemu/sysemu.h"
+#include "hw/intc/sunxi-pic.h"
+
+
+typedef struct SunxiPICState {
+    /*<  private>*/
+    SysBusDevice parent_obj;
+    /*<  public>*/
+    MemoryRegion iomem;
+    qemu_irq parent_fiq;
+    qemu_irq parent_irq;
+
Quoted 10 lines

hw/intc/sunxi-pic.c line 36

Quoted 6 lines
hw/intc/sunxi-pic.c new file +5 -0
+    uint32_t vector;
+    uint32_t base_addr;
+    uint32_t protect;
+    uint32_t nmi;
+    uint32_t irq_pending[SUNXI_PIC_REG_IDX];

IDX is a wierd choice of suffix here. Is this really a "_NUM". I'm happy as is though.

maybe, does this struct need to move to sunxi-pic.h?

Quoted 73 lines
Quoted 19 lines
hw/intc/sunxi-pic.c new file +18 -0
+    uint32_t fiq_pending[SUNXI_PIC_REG_IDX];
+    uint32_t select[SUNXI_PIC_REG_IDX];
+    uint32_t enable[SUNXI_PIC_REG_IDX];
+    uint32_t mask[SUNXI_PIC_REG_IDX];
+    /*priority setting here*/
+} SunxiPICState;
+
+static void sunxi_pic_update(SunxiPICState *s)
+{
+    uint8_t i, j;
+    bool irq = false, fiq = false;
+
+    for (i = 0, j = 0; i<  SUNXI_PIC_REG_IDX; i++) {
+        if (s->irq_pending[i] == 0&&  s->fiq_pending[i] == 0) {
+            continue;
+        }
+        for (j = 0; j<  32; j++) {
+            if (test_bit(j, (void *)&s->mask[i])) {

hw/intc/sunxi-pic.c line 64

Quoted 10 lines
hw/intc/sunxi-pic.c new file +10 -0
+                continue;
+            }
+            if (test_bit(j, (void *)&s->irq_pending[i])) {
+                irq = true;
+            }
+            if (test_bit(j, (void *)&s->fiq_pending[i])&&
+                test_bit(j, (void *)&s->select[i])) {
+                fiq = true;
+            }
+            if (irq || fiq) {

This should be an&& - the missed fiq problem i mentioned last time still isnt solved. If an early iteration of this loop sets irq then no latter iterations are given the chance to set fiq. You can only bail out of the loop if both irq and fix are set. You could just ditch this escape logic completely as I doubt its too much of a performance hit.

Quoted 20 lines
hw/intc/sunxi-pic.c new file +19 -0
+                goto out;
+            }
+        }
+    }
+
+out:
+    qemu_set_irq(s->parent_irq, irq);
+    qemu_set_irq(s->parent_fiq, fiq);
+}
+
+static void sunxi_pic_set_irq(void *opaque, int irq, int level)
+{
+    SunxiPICState *s = opaque;
+
+    if (level) {
+        set_bit(irq%32, (void *)&s->irq_pending[irq/32]);
+    }
+    sunxi_pic_update(s);
+}

hw/intc/sunxi-pic.c line 93

Quoted 10 lines
hw/intc/sunxi-pic.c new file +10 -0
+
+static uint64_t sunxi_pic_read(void *opaque, hwaddr offset, unsigned size)
+{
+    SunxiPICState *s = opaque;
+    uint8_t index = (offset&  0xc)/4;
+
+    switch (offset) {
+    case SUNXI_PIC_VECTOR:
+        return s->vector;
+        break;

Breaks after return. Fix globally.

Regards,
Peter

#3 lore raw
Quoted 90 lines · Li Guang
Quoted 77 lines · Peter Crosthwaite
Quoted 74 lines · liguang
---
  default-configs/arm-softmmu.mak |    1 +
  hw/intc/Makefile.objs           |    1 +
  hw/intc/sunxi-pic.c             |  247
+++++++++++++++++++++++++++++++++++++++
  include/hw/intc/sunxi-pic.h     |   20 +++
  4 files changed, 269 insertions(+), 0 deletions(-)

create mode 100644 hw/intc/sunxi-pic.c
create mode 100644 include/hw/intc/sunxi-pic.h

default-configs/arm-softmmu.mak +1 -0
index 7bf5ad0..bbe00e4 100644
@@ -83,3 +83,4 @@ CONFIG_SDHCI=y
  CONFIG_INTEGRATOR_DEBUG=y
 
  CONFIG_SUNXI_PIT=y
+CONFIG_SUNXI_PIC=y
hw/intc/Makefile.objs +1 -0
index 47ac442..dad8c43 100644
@@ -12,6 +12,7 @@ common-obj-$(CONFIG_IOAPIC) += ioapic_common.o
  common-obj-$(CONFIG_ARM_GIC) += arm_gic_common.o
  common-obj-$(CONFIG_ARM_GIC) += arm_gic.o
  common-obj-$(CONFIG_OPENPIC) += openpic.o
+common-obj-$(CONFIG_SUNXI_PIC) += sunxi-pic.o
 
  obj-$(CONFIG_APIC) += apic.o apic_common.o
  obj-$(CONFIG_ARM_GIC_KVM) += arm_gic_kvm.o
hw/intc/sunxi-pic.c new file +7 -0
new file mode 100644
index 0000000..a588c30
@@ -0,0 +1,247 @@
+/*
+ * Allwinner sunxi interrupt controller device emulation
+ *
+ * Copyright (C) 2013 Li Guang
+ * Written by Li Guang<[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify

it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ */

hw/intc/sunxi-pic.c new file +16 -0
+
+#include "hw/sysbus.h"
+#include "hw/devices.h"
+#include "sysemu/sysemu.h"
+#include "hw/intc/sunxi-pic.h"
+
+
+typedef struct SunxiPICState {
+    /*<  private>*/
+    SysBusDevice parent_obj;
+    /*<  public>*/
+    MemoryRegion iomem;
+    qemu_irq parent_fiq;
+    qemu_irq parent_irq;
+
+    uint32_t vector;
Quoted 10 lines

hw/intc/sunxi-pic.c line 36

Quoted 5 lines
hw/intc/sunxi-pic.c new file +4 -0
+    uint32_t base_addr;
+    uint32_t protect;
+    uint32_t nmi;
+    uint32_t irq_pending[SUNXI_PIC_REG_IDX];

IDX is a wierd choice of suffix here. Is this really a "_NUM". I'm happy as is though.

Quoted 2 lines

maybe, does this struct need to move to sunxi-pic.h?

Yes, that will be inline with Andreas' latest refactorings.

Regards,
Peter