Skip to contentSkip to conversation

mips: add Global Interrupt Controller

PATCH New Yongbok Kim 1 participant 4 messages Mar 29, 2016

lore
Share & tools
lore
#0 lore raw

v3 cover mips: add Global Interrupt Controller

This patchset implement MIPS Global Interrupt Controller.

The Global Interrupt Controller (GIC) is responsible for mapping each internal and external interrupt to the correct location for servicing.

Limitation:
Level triggering only
GIC CounterHi not implemented (Countbits = 32bits) DINT not implemented
Local WatchDog, Fast Debug Channel, Perf Counter not implemented

It is based on the earlier un-merged GIC implementation.
https://lists.gnu.org/archive/html/qemu-devel/2013-03/msg00194.html

For more information,
http://imgtec.com/mips/warrior/p-class-p5600-multiprocessor-core/
http://imgtec.com/mips/warrior/i-class-i6400-multiprocessor-core/

v3:
* rebased to top of CPS changes
* removed GCR from the patchset as CPS patchset includes it
* added checking boundaries
* fixed racy code (James)
* split gic interval timer into separate file hw/timer/mips_gictimer.c
* updated review comments (James, Leon)
* cosmetic changes

v2:
* added user mode section (James)
* moved mips_gic.c into hw/intc, mips_gcr.c into hw/misc (PeterM, PeterC)
* renamed obvious duplications (Leon)
* renamed gic_irqs into irq_state (Leon)
* removed pointer to gic IRQs from env (Leon)
* fixed loading target_ulong CMGCRBase (Leon)
* removed unimplemented registers (Leon)
* fixed writing to wedge register (Leon)
* removed magic numbers
* updated usage of map_vp to indicate not mapped
* cosmetic changes and other review comments

Leon Alrae (1):
hw/mips/cps: create GIC block inside CPS

Yongbok Kim (2):
hw/mips: implement GIC Interval Timer
hw/mips: implement Global Interrupt Controller

 hw/intc/Makefile.objs            |    1 +
 hw/intc/mips_gic.c               |  459 ++++++++++++++++++++++++++++++++++++++
 hw/mips/cps.c                    |   25 ++-
 hw/mips/mips_malta.c             |    4 +-
 hw/misc/mips_cmgcr.c             |   33 +++
 hw/timer/Makefile.objs           |    1 +
 hw/timer/mips_gictimer.c         |  141 ++++++++++++
 include/hw/intc/mips_gic.h       |  215 ++++++++++++++++++
 include/hw/mips/cps.h            |    2 +
 include/hw/misc/mips_cmgcr.h     |    9 +
 include/hw/timer/mips_gictimer.h |   46 ++++
 11 files changed, 926 insertions(+), 10 deletions(-)
 create mode 100644 hw/intc/mips_gic.c
 create mode 100644 hw/timer/mips_gictimer.c
 create mode 100644 include/hw/intc/mips_gic.h
 create mode 100644 include/hw/timer/mips_gictimer.h
#1 lore raw

PATCH v3 1/3 hw/mips: implement GIC Interval Timer

The interval timer is similar to the CP0 Count/Compare timer within each processor. The difference is the GIC_SH_COUNTER register is global to the system so that all processors have the same time reference.

To ease implementation, all VPs are having its own QEMU timer but sharing global settings and registers such as GIC_SH_CONFIG.COUTNSTOP and GIC_SH_COUNTER.

MIPS GIC Interval Timer does support upto 64 bits of Count register but in this implementation it is limited to 32 bits only.

---
 hw/timer/Makefile.objs           |    1 +
 hw/timer/mips_gictimer.c         |  141 ++++++++++++++++++++++++++++++++++++++
 include/hw/timer/mips_gictimer.h |   46 ++++++++++++
 3 files changed, 188 insertions(+), 0 deletions(-)
 create mode 100644 hw/timer/mips_gictimer.c
 create mode 100644 include/hw/timer/mips_gictimer.h
hw/timer/Makefile.objs +1 -0
index 003c14f..7ba8c23 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_OMAP) += omap_synctimer.o
 obj-$(CONFIG_PXA2XX) += pxa2xx_timer.o
 obj-$(CONFIG_SH4) += sh_timer.o
 obj-$(CONFIG_DIGIC) += digic-timer.o
+obj-$(CONFIG_MIPS_CPS) += mips_gictimer.o
 
 obj-$(CONFIG_MC146818RTC) += mc146818rtc.o
 
hw/timer/mips_gictimer.c new file +141 -0

141 lines not on this page · raw message

include/hw/timer/mips_gictimer.h new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

PATCH v3 2/3 hw/mips: implement Global Interrupt Controller

In reply to Yongbok Kim

The Global Interrupt Controller (GIC) is responsible for mapping each internal and external interrupt to the correct location for servicing.

The internal representation of registers is different from the specification in order to consolidate information for each GIC Interrupt Sources and Virtual Processors with same functionalities. For example SH_MAP00_VP00 registers are defined like each bit represents a VP but in this implementation the equivalent map_vp contains VP number in integer form for ease accesses. When it is being accessed via read write functions an internal data is converted back into the original format as the specification.

Limitations:
Level triggering only
GIC CounterHi not implemented (Countbits = 32bits) DINT not implemented
Local WatchDog, Fast Debug Channel, Perf Counter not implemented

---
 hw/intc/Makefile.objs      |    1 +
 hw/intc/mips_gic.c         |  459 ++++++++++++++++++++++++++++++++++++++++++++
 include/hw/intc/mips_gic.h |  215 +++++++++++++++++++++
 3 files changed, 675 insertions(+), 0 deletions(-)
 create mode 100644 hw/intc/mips_gic.c
 create mode 100644 include/hw/intc/mips_gic.h
hw/intc/Makefile.objs +1 -0
index 0e47f0f..fa95f77 100644
@@ -32,3 +32,4 @@ obj-$(CONFIG_ALLWINNER_A10_PIC) += allwinner-a10-pic.o
 obj-$(CONFIG_S390_FLIC) += s390_flic.o
 obj-$(CONFIG_S390_FLIC_KVM) += s390_flic_kvm.o
 obj-$(CONFIG_ASPEED_SOC) += aspeed_vic.o
+obj-$(CONFIG_MIPS_CPS) += mips_gic.o
hw/intc/mips_gic.c new file +459 -0

459 lines not on this page · raw message

include/hw/intc/mips_gic.h new file +215 -0

215 lines not on this page · raw message

Signature · 1 line
1.7.1
#3 lore raw

PATCH v3 3/3 hw/mips/cps: create GIC block inside CPS

In reply to Yongbok Kim

From: Leon Alrae <[email protected]>

Add GIC to CPS and expose its interrupt pins instead of CPU's.

---
 hw/mips/cps.c                |   25 ++++++++++++++++++-------
 hw/mips/mips_malta.c         |    4 +---
 hw/misc/mips_cmgcr.c         |   33 +++++++++++++++++++++++++++++++++
 include/hw/mips/cps.h        |    2 ++
 include/hw/misc/mips_cmgcr.h |    9 +++++++++
 5 files changed, 63 insertions(+), 10 deletions(-)
hw/mips/cps.c +18 -7
index 59e7926..ddf2294 100644
@@ -24,13 +24,8 @@
 
 qemu_irq get_cps_irq(MIPSCPSState *s, int pin_number)
 {
-    MIPSCPU *cpu = MIPS_CPU(first_cpu);
-    CPUMIPSState *env = &cpu->env;
-
     assert(pin_number < s->num_irq);
-
-    /* TODO: return GIC pins once implemented */
-    return env->irq[pin_number];
+    return s->gic.irq_state[pin_number].irq;
 }
 
 static void mips_cps_init(Object *obj)
@@ -96,6 +91,21 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
     memory_region_add_subregion(&s->container, 0,
                             sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->cpc), 0));
 
+    /* Global Interrupt Controller */
+    object_initialize(&s->gic, sizeof(s->gic), TYPE_MIPS_GIC);
+    qdev_set_parent_bus(DEVICE(&s->gic), sysbus_get_default());
+
+    object_property_set_int(OBJECT(&s->gic), s->num_vp, "num-vp", &err);
+    object_property_set_int(OBJECT(&s->gic), 128, "num-irq", &err);
+    object_property_set_bool(OBJECT(&s->gic), true, "realized", &err);
+    if (err != NULL) {
+        error_propagate(errp, err);
+        return;
+    }
+
+    memory_region_add_subregion(&s->container, 0,
+                            sysbus_mmio_get_region(SYS_BUS_DEVICE(&s->gic), 0));
+
     /* Global Configuration Registers */
     gcr_base = env->CP0_CMGCRBase << 4;
 
@@ -105,6 +115,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
     object_property_set_int(OBJECT(&s->gcr), s->num_vp, "num-vp", &err);
     object_property_set_int(OBJECT(&s->gcr), 0x800, "gcr-rev", &err);
     object_property_set_int(OBJECT(&s->gcr), gcr_base, "gcr-base", &err);
+    object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->gic.mr), "gic", &err);
     object_property_set_link(OBJECT(&s->gcr), OBJECT(&s->cpc.mr), "cpc", &err);
     object_property_set_bool(OBJECT(&s->gcr), true, "realized", &err);
     if (err != NULL) {
@@ -118,7 +129,7 @@ static void mips_cps_realize(DeviceState *dev, Error **errp)
 
 static Property mips_cps_properties[] = {
     DEFINE_PROP_UINT32("num-vp", MIPSCPSState, num_vp, 1),
-    DEFINE_PROP_UINT32("num-irq", MIPSCPSState, num_irq, 8),
+    DEFINE_PROP_UINT32("num-irq", MIPSCPSState, num_irq, 256),
     DEFINE_PROP_STRING("cpu-model", MIPSCPSState, cpu_model),
     DEFINE_PROP_END_OF_LIST()
 };
hw/mips/mips_malta.c +1 -3
index c26e953..cb55b20 100644
@@ -954,9 +954,7 @@ static void create_cps(MaltaState *s, const char *cpu_model,
 
     sysbus_mmio_map_overlap(SYS_BUS_DEVICE(s->cps), 0, 0, 1);
 
-    /* FIXME: When GIC is present then we should use GIC's IRQ 3.
-       Until then CPS exposes CPU's IRQs thus use the default IRQ 2. */
-    *i8259_irq = get_cps_irq(s->cps, 2);
+    *i8259_irq = get_cps_irq(s->cps, 3);
     *cbus_irq = NULL;
 }
 
hw/misc/mips_cmgcr.c +33 -0
index c43b61b..1d72694 100644
@@ -15,12 +15,18 @@
 #include "sysemu/sysemu.h"
 #include "hw/misc/mips_cmgcr.h"
 #include "hw/misc/mips_cpc.h"
+#include "hw/intc/mips_gic.h"
 
 static inline bool is_cpc_connected(MIPSGCRState *s)
 {
     return s->cpc_mr != NULL;
 }
 
+static inline bool is_gic_connected(MIPSGCRState *s)
+{
+    return s->gic_mr != NULL;
+}
+
 static inline void update_cpc_base(MIPSGCRState *gcr, uint64_t val)
 {
     if (is_cpc_connected(gcr)) {
@@ -34,6 +40,19 @@ static inline void update_cpc_base(MIPSGCRState *gcr, uint64_t val)
     }
 }
 
+static inline void update_gic_base(MIPSGCRState *gcr, uint64_t val)
+{
+    if (is_gic_connected(gcr)) {
+        gcr->gic_base = val & GCR_GIC_BASE_MSK;
+        memory_region_transaction_begin();
+        memory_region_set_address(gcr->gic_mr,
+                                  gcr->gic_base & GCR_GIC_BASE_GICBASE_MSK);
+        memory_region_set_enabled(gcr->gic_mr,
+                                  gcr->gic_base & GCR_GIC_BASE_GICEN_MSK);
+        memory_region_transaction_commit();
+    }
+}
+
 /* Read GCR registers */
 static uint64_t gcr_read(void *opaque, hwaddr addr, unsigned size)
 {
@@ -48,8 +67,12 @@ static uint64_t gcr_read(void *opaque, hwaddr addr, unsigned size)
         return gcr->gcr_base;
     case GCR_REV_OFS:
         return gcr->gcr_rev;
+    case GCR_GIC_BASE_OFS:
+        return gcr->gic_base;
     case GCR_CPC_BASE_OFS:
         return gcr->cpc_base;
+    case GCR_GIC_STATUS_OFS:
+        return is_gic_connected(gcr);
     case GCR_CPC_STATUS_OFS:
         return is_cpc_connected(gcr);
     case GCR_L2_CONFIG_OFS:
@@ -76,6 +99,9 @@ static void gcr_write(void *opaque, hwaddr addr, uint64_t data, unsigned size)
     MIPSGCRState *gcr = (MIPSGCRState *)opaque;
 
     switch (addr) {
+    case GCR_GIC_BASE_OFS:
+        update_gic_base(gcr, data);
+        break;
     case GCR_CPC_BASE_OFS:
         update_cpc_base(gcr, data);
         break;
@@ -100,6 +126,12 @@ static void mips_gcr_init(Object *obj)
     SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
     MIPSGCRState *s = MIPS_GCR(obj);
 
+    object_property_add_link(obj, "gic", TYPE_MEMORY_REGION,
+                             (Object **)&s->gic_mr,
+                             qdev_prop_allow_set_link_before_realize,
+                             OBJ_PROP_LINK_UNREF_ON_RELEASE,
+                             &error_abort);
+
     object_property_add_link(obj, "cpc", TYPE_MEMORY_REGION,
                              (Object **)&s->cpc_mr,
                              qdev_prop_allow_set_link_before_realize,
@@ -115,6 +147,7 @@ static void mips_gcr_reset(DeviceState *dev)
 {
     MIPSGCRState *s = MIPS_GCR(dev);
 
+    update_gic_base(s, 0);
     update_cpc_base(s, 0);
 }
 
include/hw/mips/cps.h +2 -0
index 88be765..bafdc51 100644
@@ -22,6 +22,7 @@
 
 #include "hw/sysbus.h"
 #include "hw/misc/mips_cmgcr.h"
+#include "hw/intc/mips_gic.h"
 #include "hw/misc/mips_cpc.h"
 
 #define TYPE_MIPS_CPS "mips-cps"
@@ -36,6 +37,7 @@ typedef struct MIPSCPSState {
 
     MemoryRegion container;
     MIPSGCRState gcr;
+    MIPSGICState gic;
     MIPSCPCState cpc;
 } MIPSCPSState;
 
include/hw/misc/mips_cmgcr.h +9 -0
index cc60eef..5b90e94 100644
@@ -26,7 +26,9 @@
 #define GCR_CONFIG_OFS      0x0000
 #define GCR_BASE_OFS        0x0008
 #define GCR_REV_OFS         0x0030
+#define GCR_GIC_BASE_OFS    0x0080
 #define GCR_CPC_BASE_OFS    0x0088
+#define GCR_GIC_STATUS_OFS  0x00D0
 #define GCR_CPC_STATUS_OFS  0x00F0
 #define GCR_L2_CONFIG_OFS   0x0130
 
@@ -38,6 +40,11 @@
 #define GCR_L2_CONFIG_BYPASS_SHF    20
 #define GCR_L2_CONFIG_BYPASS_MSK    ((0x1ULL) << GCR_L2_CONFIG_BYPASS_SHF)
 
+/* GCR_GIC_BASE register fields */
+#define GCR_GIC_BASE_GICEN_MSK   1
+#define GCR_GIC_BASE_GICBASE_MSK 0xFFFFFFFE0000ULL
+#define GCR_GIC_BASE_MSK (GCR_GIC_BASE_GICEN_MSK | GCR_GIC_BASE_GICBASE_MSK)
+
 /* GCR_CPC_BASE register fields */
 #define GCR_CPC_BASE_CPCEN_MSK   1
 #define GCR_CPC_BASE_CPCBASE_MSK 0xFFFFFFFF8000ULL
@@ -52,8 +59,10 @@ struct MIPSGCRState {
     hwaddr gcr_base;
     MemoryRegion iomem;
     MemoryRegion *cpc_mr;
+    MemoryRegion *gic_mr;
 
     uint64_t cpc_base;
+    uint64_t gic_base;
 };
 
 #endif /* _MIPS_GCR_H */
Signature · 1 line
1.7.1