Skip to contentSkip to conversation

hw/mips: implement Cluster Power Controller

PATCH Superseded Leon Alrae 2 participants 5 messages Feb 26, 2016 – Mar 1, 2016

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Leon Alrae

author
#0 lore raw

cover hw/mips: implement Cluster Power Controller

This minimal CPC support is one of the elements required to allow R6 Linux to bring up Virtual Processors on Malta board. This patch applies on top of Yongbok's GIC/GCR patchset which still requires updating/fixing (that probably will also affect CPC, in particular when we come up with a wrapper for the CPU, GIC, GCR, etc.). Hopefully this will get sorted out soon so we could include these functionalities in 2.6 release.

Next step can be extending the feature to support multi-core. Also, these features will be handy for testing MIPS with MTTCG which is something I hope to start in near future.

Thanks,
Leon

Leon Alrae (2):
hw/mips: add initial Cluster Power Controller support hw/mips_malta: add CPC to the Malta board

 default-configs/mips-softmmu.mak     |   1 +
 default-configs/mips64-softmmu.mak   |   1 +
 default-configs/mips64el-softmmu.mak |   1 +
 default-configs/mipsel-softmmu.mak   |   1 +
 hw/mips/mips_malta.c                 |  30 +++++++++
 hw/misc/Makefile.objs                |   1 +
 hw/misc/mips_cpc.c                   | 124 +++++++++++++++++++++++++++++++++++
 include/hw/misc/mips_cpc.h           |  45 +++++++++++++
 8 files changed, 204 insertions(+)
 create mode 100644 hw/misc/mips_cpc.c
 create mode 100644 include/hw/misc/mips_cpc.h
Signature · 1 line
2.1.0
author
#1 lore raw

PATCH 1/2 hw/mips: add initial Cluster Power Controller support

Cluster Power Controller (CPC) is responsible for power management in multiprocessing system. It provides registers to control the power and the clock frequency of the individual elements in the system.

This patch implements only three registers that are used to control the power state of each VP on a single core:
* VP Run is a write-only register used to set each VP to the run state
* VP Stop is a write-only register used to set each VP to the suspend state
* VP Running is a read-only register indicating the run state of each VP

---
 default-configs/mips-softmmu.mak     |   1 +
 default-configs/mips64-softmmu.mak   |   1 +
 default-configs/mips64el-softmmu.mak |   1 +
 default-configs/mipsel-softmmu.mak   |   1 +
 hw/misc/Makefile.objs                |   1 +
 hw/misc/mips_cpc.c                   | 124 +++++++++++++++++++++++++++++++++++
 include/hw/misc/mips_cpc.h           |  45 +++++++++++++
 7 files changed, 174 insertions(+)
 create mode 100644 hw/misc/mips_cpc.c
 create mode 100644 include/hw/misc/mips_cpc.h
default-configs/mips-softmmu.mak +1 -0
index a784644..8a9482e 100644
@@ -31,3 +31,4 @@ CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
 CONFIG_EMPTY_SLOT=y
 CONFIG_MIPS_GIC=y
+CONFIG_MIPS_CPC=y
default-configs/mips64-softmmu.mak +1 -0
index 957508d..27ca662 100644
@@ -37,3 +37,4 @@ CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
 CONFIG_EMPTY_SLOT=y
 CONFIG_MIPS_GIC=y
+CONFIG_MIPS_CPC=y
default-configs/mips64el-softmmu.mak +1 -0
index 6c1065f..7dfc4cb 100644
@@ -40,3 +40,4 @@ CONFIG_VT82C686=y
 CONFIG_ISA_TESTDEV=y
 CONFIG_EMPTY_SLOT=y
 CONFIG_MIPS_GIC=y
+CONFIG_MIPS_CPC=y
default-configs/mipsel-softmmu.mak +1 -0
index 4633b0b..e02599d 100644
@@ -31,3 +31,4 @@ CONFIG_MC146818RTC=y
 CONFIG_ISA_TESTDEV=y
 CONFIG_EMPTY_SLOT=y
 CONFIG_MIPS_GIC=y
+CONFIG_MIPS_CPC=y
hw/misc/Makefile.objs +1 -0
index 7bb14ed..46b3e71 100644
@@ -43,6 +43,7 @@ obj-$(CONFIG_ZYNQ) += zynq_slcr.o
 obj-$(CONFIG_ZYNQ) += zynq-xadc.o
 obj-$(CONFIG_STM32F2XX_SYSCFG) += stm32f2xx_syscfg.o
 obj-$(CONFIG_MIPS_GIC) += mips_gcr.o
+obj-$(CONFIG_MIPS_CPC) += mips_cpc.o
 
 obj-$(CONFIG_PVPANIC) += pvpanic.o
 obj-$(CONFIG_EDU) += edu.o
hw/misc/mips_cpc.c new file +124 -0

124 lines not on this page · raw message

include/hw/misc/mips_cpc.h new file +45 -0

45 lines not on this page · raw message

Signature · 1 line
2.1.0
#2 lore raw

Re: [Qemu-devel] [PATCH 1/2] hw/mips: add initial Cluster Power Controller support

Quoted 10 lines · Leon Alrae

Cluster Power Controller (CPC) is responsible for power management in multiprocessing system. It provides registers to control the power and the clock frequency of the individual elements in the system.

This patch implements only three registers that are used to control the power state of each VP on a single core:
* VP Run is a write-only register used to set each VP to the run state
* VP Stop is a write-only register used to set each VP to the suspend state
* VP Running is a read-only register indicating the run state of each VP

Quoted 6 lines
---
 default-configs/mips-softmmu.mak     |   1 +
 default-configs/mips64-softmmu.mak   |   1 +
 default-configs/mips64el-softmmu.mak |   1 +
 default-configs/mipsel-softmmu.mak   |   1 +

A separate thing, but maybe it would be worth having a mips-softmmu-common.mak that all the mips*-softmmu.mak include to avoid having to repeat CONFIG defines in four places like this.

Quoted 6 lines
hw/misc/mips_cpc.c new file +6 -0
+static void mips_cpc_init(Object *obj)
+{
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+    MIPSCPCState *s = MIPS_CPC(obj);
+
+    memory_region_init_io(&s->mr, OBJECT(s), &cpc_ops, s, "mips-cpc",

hw/misc/mips_cpc.c line 117

Quoted 10 lines
hw/misc/mips_cpc.c new file +10 -0
+                          CPC_ADDRSPACE_SZ);
+    sysbus_init_mmio(sbd, &s->mr);
+}
+
+static const TypeInfo mips_cpc_info = {
+    .name          = TYPE_MIPS_CPC,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(MIPSCPCState),
+    .instance_init = mips_cpc_init,
+};

I suspect you need a reset method.

hw/misc/mips_cpc.c

Quoted 13 lines
hw/misc/mips_cpc.c new file +12 -0
+
+static void mips_cpc_register_types(void)
+{
+    type_register_static(&mips_cpc_info);
+}
+
+type_init(mips_cpc_register_types)
 
+typedef struct MIPSCPCState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion mr;
+    uint64_t vp_running; /* Indicates which VP's are in the run state */

This is state, so you need a VMState structure to migrate it correctly.

Quoted 5 lines
include/hw/misc/mips_cpc.h new file +3 -1
+} MIPSCPCState;
+
+#endif /* MIPS_CPC_H */
--

2.1.0

thanks
-- PMM

author
#3 lore raw

Re: [Qemu-devel] [PATCH 1/2] hw/mips: add initial Cluster Power Controller support

Quoted 18 lines · Peter Maydell
Quoted 10 lines · Leon Alrae

Cluster Power Controller (CPC) is responsible for power management in multiprocessing system. It provides registers to control the power and the clock frequency of the individual elements in the system.

This patch implements only three registers that are used to control the power state of each VP on a single core:
* VP Run is a write-only register used to set each VP to the run state
* VP Stop is a write-only register used to set each VP to the suspend state
* VP Running is a read-only register indicating the run state of each VP

Quoted 6 lines
---
 default-configs/mips-softmmu.mak     |   1 +
 default-configs/mips64-softmmu.mak   |   1 +
 default-configs/mips64el-softmmu.mak |   1 +
 default-configs/mipsel-softmmu.mak   |   1 +
Quoted 3 lines

A separate thing, but maybe it would be worth having a mips-softmmu-common.mak that all the mips*-softmmu.mak include to avoid having to repeat CONFIG defines in four places like this.

Good idea. I'll prepare a separate patch for that.

And the comments below will be addressed in v2 (it'll also include few extra changes).

Thanks,
Leon

Quoted 45 lines
Quoted 7 lines
hw/misc/mips_cpc.c new file +6 -0
+static void mips_cpc_init(Object *obj)
+{
+    SysBusDevice *sbd = SYS_BUS_DEVICE(obj);
+    MIPSCPCState *s = MIPS_CPC(obj);
+
+    memory_region_init_io(&s->mr, OBJECT(s), &cpc_ops, s, "mips-cpc",

hw/misc/mips_cpc.c line 117

Quoted 10 lines
hw/misc/mips_cpc.c new file +10 -0
+                          CPC_ADDRSPACE_SZ);
+    sysbus_init_mmio(sbd, &s->mr);
+}
+
+static const TypeInfo mips_cpc_info = {
+    .name          = TYPE_MIPS_CPC,
+    .parent        = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(MIPSCPCState),
+    .instance_init = mips_cpc_init,
+};

I suspect you need a reset method.

hw/misc/mips_cpc.c

Quoted 13 lines
hw/misc/mips_cpc.c new file +12 -0
+
+static void mips_cpc_register_types(void)
+{
+    type_register_static(&mips_cpc_info);
+}
+
+type_init(mips_cpc_register_types)
 
+typedef struct MIPSCPCState {
+    SysBusDevice parent_obj;
+
+    MemoryRegion mr;
+    uint64_t vp_running; /* Indicates which VP's are in the run state */

This is state, so you need a VMState structure to migrate it correctly.

Quoted 5 lines
include/hw/misc/mips_cpc.h new file +3 -1
+} MIPSCPCState;
+
+#endif /* MIPS_CPC_H */
--

2.1.0

thanks
-- PMM

author
#4 lore raw

PATCH 2/2 hw/mips_malta: add CPC to the Malta board

In reply to Leon Alrae

On Malta, after reset, only VP0 on Core0 starts the execution. Other VPs are halted until VP0 powers them up using Cluster Power Controller.

---
 hw/mips/mips_malta.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
hw/mips/mips_malta.c +30 -0
index 1fb17fb..34cc4cb 100644
@@ -57,6 +57,7 @@
 #include "exec/semihost.h"
 #include "hw/misc/mips_gcr.h"
 #include "hw/intc/mips_gic.h"
+#include "hw/misc/mips_cpc.h"
 
 //#define DEBUG_BOARD_INIT
 
@@ -97,6 +98,7 @@ typedef struct {
 
     MIPSGCRState gcr;
     MIPSGICState gic;
+    MIPSCPCState cpc;
     qemu_irq *i8259;
 } MaltaState;
 
@@ -617,6 +619,19 @@ static void gic_init(MaltaState *s, Error **err)
     sysbus_mmio_map(gicbusdev, 0, gicbase);
 }
 
+static void cpc_init(MaltaState *s, Error **err)
+{
+    object_initialize(&s->cpc, sizeof(s->cpc), TYPE_MIPS_CPC);
+    qdev_set_parent_bus(DEVICE(&s->cpc), sysbus_get_default());
+
+    object_property_set_bool(OBJECT(&s->cpc), true, "realized", err);
+    if (*err != NULL) {
+        return;
+    }
+
+    sysbus_mmio_map(SYS_BUS_DEVICE(&s->cpc), 0, CPC_BASE_ADDR);
+}
+
 /* Network support */
 static void network_init(PCIBus *pci_bus)
 {
@@ -937,6 +952,7 @@ static void malta_mips_config(MIPSCPU *cpu)
 static void main_cpu_reset(void *opaque)
 {
     MIPSCPU *cpu = opaque;
+    CPUState *cs = CPU(cpu);
     CPUMIPSState *env = &cpu->env;
 
     cpu_reset(CPU(cpu));
@@ -954,6 +970,15 @@ static void main_cpu_reset(void *opaque)
         /* Start running from the bootloader we wrote to end of RAM */
         env->active_tc.PC = 0x40000000 + loaderparams.ram_low_size;
     }
+
+    /* At reset only VP0 on Core0 will start executing the code, other
+       VPs are halted until VP0 powers them up through Cluster Power
+       Controller. */
+    if ((env->CP0_Config5 & (1 << CP0C5_VP)) &&
+        (env->CP0_Config3 & (1 << CP0C3_CMGCR)) &&
+        (cs->cpu_index != 0)) {
+        cs->halted = 1;
+    }
 }
 
 static
@@ -1200,6 +1225,11 @@ void mips_malta_init(MachineState *machine)
             error_report("%s", error_get_pretty(err));
             exit(1);
         }
+        cpc_init(s, &err);
+        if (err != NULL) {
+            error_report("%s", error_get_pretty(err));
+            exit(1);
+        }
     }
 
     /*
Signature · 1 line
2.1.0